Skip to content

Merge pull request #3 from Goldchae/newcode/#0 #1

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

Merge pull request #3 from Goldchae/newcode/#0 #1

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@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Log in to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push Docker image
uses: docker/build-push-action@v2
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ env.DOCKER_IMAGE }}:latest
deploy-to-ec2:
needs: build-and-push-docker
runs-on: ubuntu-latest
steps:
- name: Deploying to AWS EC2
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USER }}
key: ${{ secrets.EC2_SSH_PRIVATE_KEY }}
script: |
docker pull ${{ env.DOCKER_IMAGE }}:latest
docker stop qup-frontend || true
docker rm qup-frontend || true
docker run -d --name qup-frontend -p 80:80 ${{ env.DOCKER_IMAGE }}:latest