Skip to content

Commit

Permalink
Add demo deployment to CICD workflow.
Browse files Browse the repository at this point in the history
  • Loading branch information
cmvanb committed Sep 18, 2024
1 parent 6c24915 commit adcbbc5
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Docker Image CI
name: Docker Image CI/CD

on:
push:
Expand All @@ -9,6 +9,14 @@ on:
env:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKERHUB_ACCESS_TOKEN: ${{ secrets.DOCKERHUB_ACCESS_TOKEN }}
HOST: ${{ secrets.DEMO_HOST }}
USER: ${{ secrets.DEMO_USER }}
SSH_PORT: ${{ secrets.DEMO_SSH_PORT }}
SSH_PRIVATE_KEY: ${{ secrets.DEMO_SSH_PRIVATE_KEY }}
ENV_SECRET_KEY: ${{ secrets.DEMO_ENV_SECRET_KEY }}
ENV_VIRTUAL_HOST: ${{ secrets.DEMO_ENV_VIRTUAL_HOST }}
ENV_VIRTUAL_PORT: ${{ secrets.DEMO_ENV_VIRTUAL_PORT }}
ENV_LETSENCRYPT_HOST: ${{ secrets.DEMO_ENV_LETSENCRYPT_HOST }}

jobs:
build:
Expand Down Expand Up @@ -41,3 +49,34 @@ jobs:
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

deploy:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup SSH
run: sudo apt-get install -y openssh-client

- name: Deploy to demo server
run: |
echo "$SSH_PRIVATE_KEY" > private_key.pem
chmod 600 private_key.pem
echo "SECRET_KEY=$ENV_SECRET_KEY" > ./deployment/.env
echo "VIRTUAL_HOST=$ENV_VIRTUAL_HOST" >> ./deployment/.env
echo "VIRTUAL_PORT=$ENV_VIRTUAL_PORT" >> ./deployment/.env
echo "LETSENCRYPT_HOST=$ENV_LETSENCRYPT_HOST" >> ./deployment/.env
rsync \
--human-readable \
--verbose \
--recursive \
--archive \
--delete-after \
--exclude='.git' \
--rsh="ssh -Tv -o StrictHostKeyChecking=no -i private_key.pem -p $SSH_PORT" \
./cookbook $USER@$HOST:"/home/$USER"
ssh -i private_key.pem -p $SSH_PORT -t $USER@$HOST \
"cd cookbook && sudo docker compose -f deployment/demo.yml down && sudo docker compose -f deployment/demo.yml pull && sudo docker compose -f deployment/demo.yml up -d"
rm -f private_key.pem

0 comments on commit adcbbc5

Please sign in to comment.