Merge pull request #26 from 5wonju/feat/#21-navbar #20
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }}/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 |