Skip to content

ci: add prod compose and deploy (#49) #10

ci: add prod compose and deploy (#49)

ci: add prod compose and deploy (#49) #10

Workflow file for this run

name: deploy
on:
push:
tags:
- 'v*.*.*'
env:
TAG: ${{github.ref_name}}
IMAGE_NAME: ${{ vars.IMAGE_NAME }}
DOCKER_REGISTRY: ${{ secrets.DOCKER_REGISTRY }}
DOCKER_HUB_USER: ${{ secrets.DOCKER_HUB_USER }}
DOCKER_HUB_PASS: ${{ secrets.DOCKER_HUB_PASS }}
jobs:
publish-dotnet:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Build the Docker image
run: docker build ./Foodie --tag $IMAGE_NAME:$TAG
- name: Publish image
run: |
docker login -u $DOCKER_HUB_USER -p $DOCKER_HUB_PASS
docker tag $IMAGE_NAME:$TAG $DOCKER_REGISTRY/$IMAGE_NAME:$TAG
docker push $DOCKER_REGISTRY/$IMAGE_NAME:$TAG
deploy:
runs-on: ubuntu-latest
needs: [publish-dotnet]
steps:
- name: setup env and docker compose up
uses: appleboy/ssh-action@master
env:
CERT_KEY_PATH: ${{ secrets.CERT_KEY_PATH }}
CERT_PATH: ${{ secrets.CERT_PATH }}
PRIVATE_KEY: ${{ secrets.PRIVATE_KEY }}
CERTIFICATE: ${{ secrets.CERTIFICATE }}
NGINX_CONF: ${{ secrets.NGINX_CONF }}
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
password: ${{ secrets.PASSWORD }}
envs: TAG,IMAGE_NAME,DOCKER_REGISTRY,CERT_KEY_PATH,CERT_PATH,PRIVATE_KEY,CERTIFICATE,NGINX_CONF
script: |
rm -rf repo
git clone https://github.com/${{github.repository}} repo && cd repo
git fetch origin $TAG
git checkout $TAG
chmod +x ./setup_env.sh
./setup_env.sh
docker-compose -f docker-compose.prod.yml down
docker-compose -f docker-compose.prod.yml up -d