-
Notifications
You must be signed in to change notification settings - Fork 7
53 lines (40 loc) · 1.82 KB
/
deploy-docker.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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