Skip to content

Commit

Permalink
infra: nginx docker file build
Browse files Browse the repository at this point in the history
  • Loading branch information
Hoya324 committed Nov 11, 2024
1 parent c714ae3 commit 485631d
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions .github/workflows/nginx.yml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 485631d

Please sign in to comment.