애자일허브 backend PROD CD #2
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: 애자일허브 backend PROD CD | |
env: | |
DOCKER_HUB_REPOSITORY: ${{ secrets.DOCKERHUB_USERNAME }}/agilehub-backend | |
on: | |
workflow_dispatch: | |
push: | |
branches: | |
- main | |
paths: | |
- "src/**" | |
jobs: | |
backend-docker-build-and-push: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v3 | |
- name: Setup Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
# Docker Buildx를 설정한다 | |
- name: Login to Docker Hub | |
uses: docker/[email protected] | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Build and Push | |
uses: docker/build-push-action@v2 | |
with: | |
context: ./ | |
# Dockerfile이 있는 위치 | |
file: ./Dockerfile | |
# Dockerfile의 이름 | |
push: true | |
# 이미지를 레지스트리에 푸시 | |
tags: ${{ env.DOCKER_HUB_REPOSITORY }}:${{ github.sha }} | |
platforms: linux/amd64,linux/arm64,windows/amd64 | |
backend-docker-pull-and-run: | |
needs: [ backend-docker-build-and-push ] | |
if: ${{ needs.backend-docker-build-and-push.result == 'success' }} | |
runs-on: [ self-hosted, evo-actions ] | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Setup SSH Key | |
run: | | |
echo "${{ secrets.PEM_KEY }}" > pem_key | |
chmod 600 pem_key | |
- name: WAS인스턴스 접속 및 애플리케이션 실행 | |
run: | | |
ssh -i pem_key -o StrictHostKeyChecking=no ${{ secrets.WAS_USERNAME }}@${{ secrets.WAS_PUBLIC_IP }} << EOF | |
docker rm -f agilehub-backend || true | |
docker pull ${{ env.DOCKER_HUB_REPOSITORY }}:${{ github.sha }} | |
docker run -d -p 8080:8080 --name agilehub-backend ${{ env.DOCKER_HUB_REPOSITORY }}:${{ github.sha }} | |
EOF |