Deploy Docker #39
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: Deploy Docker | |
on: | |
workflow_run: | |
workflows: | |
- 'Build and push Docker' | |
types: | |
- completed | |
workflow_dispatch: | |
env: | |
IMAGE_NAME_WITH_TAG: ${{ secrets.DOCKER_USERNAME }}/${{ github.event.repository.name }}:latest | |
PROJECT_FOLDER_ABSOLUTE_PATH: /home/ubuntu/traefik-proxy/apps/${{ github.event.repository.name }} | |
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 ${{ env.PROJECT_FOLDER_ABSOLUTE_PATH }} | |
# 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 }})" | |
export MY_UID=$(id -u) MY_GID=$(id -g) | |
echo "MY_UID: $MY_UID and MY_GID: $MY_GID" | |
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 |