CD #19
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CD | |
env: | |
DOCKER_IMAGE: ghcr.io/likelion-knu04/mealog-web | |
DOCKER_CONTAINER: mealog-web | |
on: | |
workflow_run: | |
workflows: ['CI'] | |
types: | |
- completed | |
jobs: | |
deploy: | |
name: Deploy | |
runs-on: self-hosted | |
steps: | |
- name: Login to ghcr | |
uses: docker/login-action@v2 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GHCR_TOKEN }} | |
- name: Pull Docker image | |
run: sudo docker pull ${{ env.DOCKER_IMAGE }}:latest | |
- name: Delete old Docker container and image | |
run: | | |
docker stop ${{ env.DOCKER_CONTAINER }} || true | |
docker rm -f ${{ env.DOCKER_CONTAINER }} || true | |
docker rmi ${{ env.DOCKER_IMAGE }}:latest || true | |
- name: Run Docker container | |
run: sudo docker run -d -p 3000:3000 --name ${{ env.DOCKER_CONTAINER }} --restart always --hostname ${{ env.DOCKER_CONTAINER }} --network web ${{ env.DOCKER_IMAGE }}:latest |