Skip to content

Deploy Docker

Deploy Docker #12

Workflow file for this run

name: Deploy Docker
on:
workflow_run:
workflows: ['Build and push Docker - disabled']
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/[email protected]
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/nmc-docker
# 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 }}
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