Merge pull request #34 from CodeLit/CodeLit-patch-1 #21
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: Host-deploy | |
on: | |
push: | |
branches: [ main ] | |
workflow_dispatch: # Allows you to run this workflow manually from the Actions tab | |
jobs: | |
build-and-push: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- uses: actions/upload-artifact@v3 | |
with: | |
name: job-artifact | |
path: docker-compose.yml | |
- name: Docker-compose build | |
run: docker-compose build | |
- name: Log in to Docker Hub | |
uses: docker/login-action@v2 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GHCR_TOKEN }} | |
- name: Push to Docker Hub | |
run: docker-compose push | |
deploy: | |
runs-on: ubuntu-latest | |
needs: build-and-push | |
steps: | |
- uses: actions/download-artifact@v3 | |
with: | |
name: job-artifact | |
- name: Copy files via ssh | |
uses: appleboy/scp-action@master | |
with: | |
host: ${{ vars.SSH_HOST }} | |
username: ${{ vars.SSH_USERNAME }} | |
key: ${{ secrets.SSH_PRIVATE_KEY }} | |
port: 22 | |
source: 'docker-compose.yml' | |
target: '${{ vars.SSH_PROJECT_FOLDER }}' | |
- name: Run commands via ssh | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ vars.SSH_HOST }} | |
username: ${{ vars.SSH_USERNAME }} | |
key: ${{ secrets.SSH_PRIVATE_KEY }} | |
port: 22 | |
script: | | |
cd ${{ vars.SSH_PROJECT_FOLDER }} | |
echo $GHCR_TOKEN | docker login ghcr.io -u ${{ github.actor }} --password-stdin | |
docker-compose down | |
docker-compose pull | |
docker-compose up -d --remove-orphans |