Skip to content

Merge pull request #7 from Goldchae/newcode/#0 #5

Merge pull request #7 from Goldchae/newcode/#0

Merge pull request #7 from Goldchae/newcode/#0 #5

Workflow file for this run

name: Deploy to AWS EC2 using Docker
on:
push:
branches:
- main
env:
DOCKER_IMAGE: qup-frontend
jobs:
build-and-push-docker:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push Docker image
uses: docker/build-push-action@v3
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ env.DOCKER_IMAGE }}:latest, ${{ env.DOCKER_IMAGE }}:${{ github.sha }}
deploy-to-ec2:
needs: build-and-push-docker
runs-on: ubuntu-latest
steps:
- name: Deploying to AWS EC2
uses: appleboy/[email protected]
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USER }}
key: ${{ secrets.EC2_SSH_PRIVATE_KEY }}
script: |
if ! docker pull ${{ env.DOCKER_IMAGE }}:latest; then
echo "Failed to pull the latest image."
exit 1
fi
docker stop qup-frontend || true
docker rm qup-frontend || true
docker run -d --name qup-frontend -p 80:80 ${{ env.DOCKER_IMAGE }}:latest