-
Notifications
You must be signed in to change notification settings - Fork 0
92 lines (81 loc) ยท 3.12 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
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: Push to GitLab frontend branch
env:
GITLAB_TOKEN: ${{ secrets.GITLAB_TOKEN }}
run: |
git checkout deploy
git pull origin deploy
git checkout -b frontend
git filter-branch --force --prune-empty --index-filter "git rm -rf --cached --ignore-unmatch .github" HEAD
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 }}/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 }}/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 }}/frontend:v${{ github.run_number }}
docker run --name frontend -d \
-p 3000:3000 \
--network=bridge \
--restart unless-stopped \
${{ secrets.DOCKERHUB_USERNAME }}/frontend:v${{ github.run_number }}
docker container prune -f
docker images | grep '${{ secrets.DOCKERHUB_USERNAME }}/frontend' | grep -v 'v${{ github.run_number }}' | awk '{print $3}' | xargs -r docker rmi