-
Notifications
You must be signed in to change notification settings - Fork 0
138 lines (125 loc) ยท 4.92 KB
/
action.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
name: deployment
on:
push:
branches:
- deploy
jobs:
push-to-gitlab:
runs-on: ubuntu-latest
steps:
- name: Checkout the repository
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Configure Git
run: |
git config user.name "์ด์ฐ์ฑ"
git config user.email "[email protected]"
- name: Setup Python and Install git filter-repo
uses: actions/setup-python@v2
with:
python-version: "3.12.3"
- name: Install git filter-repo
run: pip install git-filter-repo
- name: Rewrite Commit Author and Committer Information and Message
run: |
git checkout deploy
git pull origin deploy
git checkout -b frontend
git filter-repo --force --commit-callback '
import re
name = commit.author_name.decode("utf-8")
email = ""
if name == "์ด์์ฃผ" or name == "Lee Wonju":
name = "์ด์์ฃผ"
email = "[email protected]"
elif name == "์ด์ฐ์ฑ" or name == "leewooseong":
name = "์ด์ฐ์ฑ"
email = "[email protected]"
elif name == "์ด์ฌ๋ฏผ" or name == "JaeMin Lee" or name == "Chosamee":
name = "์ด์ฌ๋ฏผ"
email = "[email protected]"
else:
return
commit.author_email = email.encode()
commit.committer_email = email.encode()
commit.author_name = name.encode()
commit.committer_name = name.encode()
'
git filter-repo --force --message-callback '
import re
if re.search(b"https://github.com/5wonju", message):
return b"Merge branch '\''frontend'\''"
elif b"5wonju/" in message:
return message.replace(b"5wonju/", b"")
return message
'
git filter-repo --force --commit-callback '
import re
author_name = commit.author_name.decode("utf-8")
if author_name == "์ ์ฐฝ์ฝ":
return
if b"deploy" in commit.message:
commit.message = commit.message.replace(b"deploy", b"frontend")
'
git filter-branch --force --prune-empty --index-filter "git rm -rf --cached --ignore-unmatch .github" HEAD
- name: Push to GitLab frontend branch
env:
GITLAB_TOKEN: ${{ secrets.GITLAB_TOKEN }}
run: |
git remote add gitlab https://oauth2:[email protected]/s10-final/S10P31D206.git
git push gitlab frontend:frontend --force
git checkout deploy
git branch -D frontend
build-and-push:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Log in to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
# - name: .env setting
# run: |
# echo "VITE_DEPLOY_BASE_URL=${{ secrets.VITE_DEPLOY_BASE_URL }}" >> frontend/.env
# echo "VITE_GOOGLE_CLIENT_ID=${{ secrets.VITE_GOOGLE_CLIENT_ID }}" >> frontend/.env
# echo "VITE_GOOGLE_REDIRECT_URI=${{ secrets.VITE_GOOGLE_REDIRECT_URI }}" >> frontend/.env
# echo "VITE_KAKAO_REST_API_KEY=${{ secrets.VITE_KAKAO_REST_API_KEY }}" >> frontend/.env
# echo "VITE_KAKAO_REDIRECT_URI=${{ secrets.VITE_KAKAO_REDIRECT_URI }}" >> frontend/.env
- name: Push Docker image with tag
uses: docker/build-push-action@v2
with:
context: ./frontend
file: frontend/Dockerfile
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/5wonju-frontend:v${{ github.run_number }}
- name: Push Docker image latest
uses: docker/build-push-action@v2
with:
context: ./frontend
file: frontend/Dockerfile
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/5wonju-frontend
deploy:
needs: build-and-push
runs-on: ubuntu-latest
steps:
- name: Deploy to EC2
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USER }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
docker stop frontend || true
docker rm frontend || true
docker pull ${{ secrets.DOCKERHUB_USERNAME }}/5wonju-frontend:v${{ github.run_number }}
docker run --name frontend -d \
-p 3000:3000 \
--network=bridge \
--restart unless-stopped \
${{ secrets.DOCKERHUB_USERNAME }}/5wonju-frontend:v${{ github.run_number }}
docker container prune -f
docker images | grep '${{ secrets.DOCKERHUB_USERNAME }}/5wonju-frontend' | grep -v 'v${{ github.run_number }}' | awk '{print $3}' | xargs -r docker rmi