Skip to content

Commit d8862dc

Browse files
committed
fixup! chore: manage docker bloat on deployments
Signed-off-by: Luiz Georg <luiz.georg@profusion.mobi>
1 parent fa79939 commit d8862dc

3 files changed

Lines changed: 70 additions & 13 deletions

File tree

.github/workflows/deploy-production.yaml

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ jobs:
8888
needs: start-notification
8989
runs-on: ubuntu-latest
9090
steps:
91-
- name: Configure host authenticity
91+
- &ssh-host-auth
92+
name: Configure host authenticity
9293
run: |
9394
mkdir -p ~/.ssh/ && chmod 700 ~/.ssh/
9495
touch ~/.ssh/known_hosts && chmod 600 ~/.ssh/known_hosts
@@ -106,16 +107,35 @@ jobs:
106107
cp ~/.env-production dashboard-production/.env &&
107108
cd dashboard-production &&
108109
git checkout ${GITHUB_SHA} &&
109-
docker compose up --pull=always --remove-orphans --detach &&
110-
docker image prune -fa --filter "until=48h" &&
111-
docker volume ls --filter dangling=true --format "::warning::volume {{.Name}} is dangling" &&
112-
docker container ls -f status=exited --format "::warning::container {{.ID}} {{.Status}} ({{.Names}})"
110+
docker compose -f docker-compose-next.yml pull --policy=always &&
111+
docker compose -f docker-compose-next.yml up -d --remove-orphans
113112
"
114113
env:
115114
SSH_USER: ${{ secrets.STAGING_USER }}
116115
SSH_HOST: ${{ secrets.STAGING_HOST }}
117116
SSH_KEY: ${{ secrets.STAGING_KEY }}
118117

118+
cleanup:
119+
needs: deploy-production
120+
runs-on: ubuntu-latest
121+
steps:
122+
- *ssh-host-auth
123+
- name: Prune docker artifacts on remote
124+
env:
125+
SSH_USER: ${{ secrets.STAGING_USER }}
126+
SSH_HOST: ${{ secrets.STAGING_HOST }}
127+
SSH_KEY: ${{ secrets.STAGING_KEY }}
128+
run: |
129+
eval $(ssh-agent -s)
130+
echo "$SSH_KEY" | ssh-add - >/dev/null
131+
ssh "${SSH_USER}@${SSH_HOST}" <<<'EOF'
132+
set -eu
133+
docker image prune -fa --filter "until=48h"
134+
docker builder prune -f --filter "until=48h"
135+
docker volume ls --filter dangling=true --format "::warning::volume {{.Name}} is dangling"
136+
docker container ls --filter status=exited --format "::warning::container {{.ID}} {{.Status}} ({{.Names}})"
137+
EOF
138+
119139
- name: Discord notification on success
120140
if: success()
121141
env:

.github/workflows/deploy-staging.yaml

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,15 @@ jobs:
4949
needs: check-migrations
5050
runs-on: ubuntu-latest
5151
steps:
52-
- name: Configure staging host authenticity
52+
- &ssh-host-auth
53+
name: Configure staging host authenticity
5354
run: |
5455
mkdir -p ~/.ssh/ && chmod 700 ~/.ssh/
5556
touch ~/.ssh/known_hosts && chmod 600 ~/.ssh/known_hosts
5657
echo "$SSH_HOSTKEY" > ~/.ssh/known_hosts
5758
env:
5859
SSH_HOSTKEY: ${{ secrets.STAGING_HOSTKEY }}
59-
60+
6061
- name: Deploy to staging
6162
run: |
6263
eval $(ssh-agent -s)
@@ -67,16 +68,36 @@ jobs:
6768
cp ~/.env-staging dashboard-staging/.env &&
6869
cd dashboard-staging &&
6970
git checkout ${GITHUB_SHA} &&
70-
docker compose up --build --pull=always --remove-orphans --detach &&
71-
docker image prune -fa --filter "until=48h" &&
72-
docker volume ls --filter dangling=true --format "::warning::volume {{.Name}} is dangling" &&
73-
docker container ls -f status=exited --format "::warning::container {{.ID}} {{.Status}} ({{.Names}})"
71+
docker compose pull --ignore-buildable --policy=always &&
72+
docker compose build --no-cache &&
73+
docker compose up -d --remove-orphans
7474
"
7575
env:
7676
SSH_USER: ${{ secrets.STAGING_USER }}
7777
SSH_HOST: ${{ secrets.STAGING_HOST }}
7878
SSH_KEY: ${{ secrets.STAGING_KEY }}
7979

80+
cleanup:
81+
needs: deploy-staging
82+
runs-on: ubuntu-latest
83+
steps:
84+
- *ssh-host-auth
85+
- name: Prune docker artifacts on remote
86+
env:
87+
SSH_USER: ${{ secrets.STAGING_USER }}
88+
SSH_HOST: ${{ secrets.STAGING_HOST }}
89+
SSH_KEY: ${{ secrets.STAGING_KEY }}
90+
run: |
91+
eval $(ssh-agent -s)
92+
echo "$SSH_KEY" | ssh-add - >/dev/null
93+
ssh "${SSH_USER}@${SSH_HOST}" <<<'EOF'
94+
set -eu
95+
docker image prune -fa --filter "until=48h"
96+
docker builder prune -f --filter "until=48h"
97+
docker volume ls --filter dangling=true --format "::warning::volume {{.Name}} is dangling"
98+
docker container ls --filter status=exited --format "::warning::container {{.ID}} {{.Status}} ({{.Names}})"
99+
EOF
100+
80101
e2e-tests:
81102
runs-on: ubuntu-latest
82103
timeout-minutes: 10

.github/workflows/staging-db.yaml

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,23 @@ jobs:
2424
git fetch
2525
git checkout ${{ github.event.inputs.GIT_BRANCH }}
2626
cd ..
27-
docker compose -f docker-compose-all.yaml --profile=self-hosted up --build --pull=always --remove-orphans --detach
27+
docker compose -f docker-compose-all.yaml --profile=self-hosted pull --ignore-buildable
28+
docker compose -f docker-compose-all.yaml --profile=self-hosted build
29+
docker compose -f docker-compose-all.yaml --profile=self-hosted up -d --remove-orphans
30+
31+
cleanup:
32+
runs-on: ubuntu-latest
33+
needs: deploy
34+
steps:
35+
- name: Prune docker artifacts on remote
36+
uses: appleboy/ssh-action@v1
37+
with:
38+
host: ${{ secrets.DB_SSH_HOST }}
39+
username: ${{ secrets.DB_SSH_USER }}
40+
key: ${{ secrets.DB_SSH_KEY }}
41+
script: |
42+
set -eu
2843
docker image prune -fa --filter "until=48h"
44+
docker builder prune -f --filter "until=48h"
2945
docker volume ls --filter dangling=true --format "::warning::volume {{.Name}} is dangling"
30-
docker container ls -f status=exited --format "::warning::container {{.ID}} {{.Status}} ({{.Names}})"
46+
docker container ls --filter status=exited --format "::warning::container {{.ID}} {{.Status}} ({{.Names}})"

0 commit comments

Comments
 (0)