Skip to content

Deploy Docker

Deploy Docker #8

Workflow file for this run

name: Deploy Docker
on:
workflow_run:
workflows:
- 'disabled-Build and push Docker'
types:
- completed
workflow_dispatch:
env:
IMAGE_NAME_WITH_TAG: ${{ secrets.DOCKER_USERNAME }}/${{ github.event.repository.name }}:latest
jobs:
deploy:
name: Deploy image from Dockerhub to remote host with ssh
runs-on: ubuntu-latest
steps:
- name: Deploy latest image
uses: appleboy/ssh-action@v1.2.0
with:
host: ${{ secrets.REMOTE_HOST }}
username: ${{ secrets.REMOTE_USERNAME }}
key: ${{ secrets.REMOTE_KEY_ED25519 }}
port: ${{ secrets.REMOTE_PORT }}
# don't stop on errors
script_stop: false
script: |
cd /home/ubuntu/traefik-proxy/apps/products-page
# Docker login for private image
echo "${{ secrets.DOCKER_PASSWORD }} | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin"
echo "Old image tag: $(docker inspect --format '{{ index .RepoTags 0 }}' ${{ env.IMAGE_NAME_WITH_TAG }})"
echo "Old image hash: $(docker inspect --format '{{ index .RepoDigests 0 }}' ${{ env.IMAGE_NAME_WITH_TAG }})"
docker compose down
docker image rm ${{ env.IMAGE_NAME_WITH_TAG }} || true
docker compose up -d
echo "New image tag: $(docker inspect --format '{{ index .RepoTags 0 }}' ${{ env.IMAGE_NAME_WITH_TAG }})"
echo "New image hash: $(docker inspect --format '{{ index .RepoDigests 0 }}' ${{ env.IMAGE_NAME_WITH_TAG }})"
# remove dangling images, optional
# docker image prune -af