From 485631daf9f9a201b42cfc7daae763334a4d1edc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=82=98=EA=B2=BD=ED=98=B8?= Date: Mon, 11 Nov 2024 16:42:38 +0900 Subject: [PATCH] infra: nginx docker file build --- .github/workflows/nginx.yml | 52 +++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 .github/workflows/nginx.yml diff --git a/.github/workflows/nginx.yml b/.github/workflows/nginx.yml new file mode 100644 index 0000000..89f8965 --- /dev/null +++ b/.github/workflows/nginx.yml @@ -0,0 +1,52 @@ +name: NGINX Deployment Workflow + +on: + workflow_dispatch: + +permissions: + contents: read + +jobs: + deploy_nginx: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + # Docker Hub에 로그인 + - name: Log in to Docker Hub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + # Dockerfile.nginx Build & push + - name: Build and push NGINX Docker image + uses: docker/build-push-action@v3 + with: + context: . + file: ./docker/Dockerfile.nginx + push: true + tags: ${{ secrets.DOCKER_REPO }}:nginx-${{ github.run_number }} + + deploy_to_ec2: + runs-on: ubuntu-latest + needs: deploy_nginx + + steps: + - name: Configure SSH for EC2 + uses: appleboy/ssh-action@master + with: + host: ${{ secrets.PUBLIC_DNS }} + username: ${{ secrets.USERNAME }} + key: ${{ secrets.PEM_KEY }} + script: | + echo ${{ secrets.DOCKER_PASSWORD }} | sudo docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin + sudo docker pull ${{ secrets.DOCKER_REPO }}:nginx-${{ github.run_number }} + + if [ "$(sudo docker ps -q -f name=nginx)" ]; then + sudo docker stop nginx && sudo docker rm nginx + fi + sudo docker run -d --name nginx -p 80:80 -p 443:443 ${{ secrets.DOCKER_REPO }}:nginx-${{ github.run_number }} + debug: true