애자일허브 backend PROD CD #6
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 | |
- 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: ./ | |
file: ./Dockerfile | |
push: true | |
tags: ${{ env.DOCKER_HUB_REPOSITORY }}:${{ github.sha }} | |
platforms: linux/amd64,linux/arm64,windows/amd64 | |
attempt-with-first-runner: | |
needs: [ backend-docker-build-and-push ] | |
if: ${{ needs.backend-docker-build-and-push.result == 'success' }} | |
runs-on: [ self-hosted, enble-runner ] | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Setup SSH Key | |
run: | | |
echo "${{ secrets.PEM_KEY }}" > pem_key | |
chmod 600 pem_key | |
shell: bash | |
- 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 | |
shell: bash | |
attempt-with-second-runner: | |
needs: [ attempt-with-first-runner ] | |
if: needs.attempt-with-first-runner.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 |