Skip to content

Deploy: Disable GitHub Actions #126

Deploy: Disable GitHub Actions

Deploy: Disable GitHub Actions #126

Workflow file for this run

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 "sitpo96@naver.com"
- 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 = "turtle4265@naver.com"
elif name == "์ด์šฐ์„ฑ" or name == "leewooseong":
name = "์ด์šฐ์„ฑ"
email = "sitpo96@naver.com"
elif name == "์ด์žฌ๋ฏผ" or name == "JaeMin Lee" or name == "Chosamee":
name = "์ด์žฌ๋ฏผ"
email = "cytor@naver.com"
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:$GITLAB_TOKEN@lab.ssafy.com/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 "${{ secrets.NEXT_PUBLIC_BASE_URL }}" >> frontend/.env.production
echo "${{ secrets.NEXT_PUBLIC_CLIENT_ID }}" >> frontend/.env.production
- 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