Skip to content

Workflow file for this run

name: Deploy Server
on:
push:
branches:
- master
- docker
paths:
- packages/image-search-server/src/**
- packages/image-search-server/package.json
jobs:
check-credentials:
name: Check for SSH credentials
runs-on: ubuntu-latest
environment: production
outputs:
is_set: ${{ steps.check.outputs.is_set }}
steps:
- name: Perform check
id: check
run: |
if [[ '${{ secrets.SSH_KEY }}' && '${{ secrets.SSH_HOST }}' && '${{ secrets.SSH_USERNAME }}' ]]; then
echo "is_set=true" >> "$GITHUB_OUTPUT"
else
echo "is_set=false" >> "$GITHUB_OUTPUT"
echo "SSH credentials are not set. Skipping deployment."
fi
check-package:
name: Check package
needs: check-credentials
if: ${{ needs.check-credentials.outputs.is_set == 'true' }}
uses: ./.github/workflows/check.yml
secrets: inherit
with:
cwd: packages/image-search-server
deploy:
name: Deploy server
runs-on: ubuntu-latest
needs: check-package
environment: production
steps:
- name: Checkout repo
uses: actions/checkout@cbb722410c2e876e24abbe8de2cc27693e501dcb
- name: Build image
run: docker build --pull --rm -f 'Dockerfile' -t image-search-server:latest '.' && docker save -o image-search-server.tar image-search-server:latest
- name: Package image
run: gzip image-search-server.tar
- name: Setup SSH
run: |
mkdir -p ~/.ssh
echo '${{ secrets.SSH_KEY }}' > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
echo 'StrictHostKeyChecking no' >> ~/.ssh/config
- name: Deploy image
run: scp image-search-server.tar.gz docker-compose.yml ${{ secrets.SSH_USERNAME }}@${{ secrets.SSH_HOST }}:/tmp/
- name: Run container
uses: appleboy/ssh-action@66aa4d343bf909ac4fa0ac52f4e62a9adc354c95
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_KEY }}
script: |
if [[ ! -d "/image-search-server" ]]; then
echo "Create the /image-search-server folder with the .env file in it first.\nIt is also recommended to run 'chown -R root:docker /image-search-server && chmod -R 770 /image-search-server' for security reasons" >&2
exit 1
fi
cd /image-search-server
docker-compose down
docker rmi image-search-server:latest
mv -f /tmp/image-search-server.tar.gz /tmp/docker-compose.yml ./
docker load -i image-search-server.tar.gz
docker-compose up -d