Skip to content
This repository has been archived by the owner on Oct 22, 2024. It is now read-only.

Merge pull request #29 from racheliee/28-implement-creating-achieveme… #50

Merge pull request #29 from racheliee/28-implement-creating-achieveme…

Merge pull request #29 from racheliee/28-implement-creating-achieveme… #50

name: Docker Image CI
on:
push:
paths:
- backend/main/**
- .github/workflows/nestjsBackend_CICD.yml
branches: ["main"]
defaults:
run:
working-directory: "./backend/main"
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Login Dockerhub
run: docker login -u ${{secrets.DOCKERHUB_USERNAME}} -p ${{secrets.DOCKERHUB_PASSWORD}}
- name: Build the Docker image
run: docker build --platform linux/amd64 -t ${{secrets.DOCKERHUB_USERNAME}}/sprout-backend:latest .
- name: push
run: docker push ${{secrets.DOCKERHUB_USERNAME}}/sprout-backend:latest
deploy:
needs: build-and-push
runs-on: ubuntu-latest
steps:
- name: Deploy
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST }} # EC2 인스턴스 퍼블릭 DNS
username: ec2-user
key: ${{ secrets.PRIVATE_KEY }} # pem 키
# 도커 작업
script: |
docker pull ${{ secrets.DOCKERHUB_USERNAME }}/sprout-backend:latest
docker stop main
docker remove main
docker run -d --log-driver=syslog -p 8000:8000 --network app --env-file .env --name main ${{ secrets.DOCKERHUB_USERNAME }}/sprout-backend:latest
docker image prune -a -f