Skip to content

Commit

Permalink
Label multistage build sources so they can be deleted on destroy
Browse files Browse the repository at this point in the history
In cases where docker image prune or --filter=since would have minor adverse effects on other projects, so it can even be run in local environments
  • Loading branch information
andytson-inviqa committed Jan 21, 2021
1 parent b1908f9 commit bf843bc
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/_base/docker/image/php-fpm/Dockerfile.twig
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{% if @('app.build') == 'static' %}
FROM {{ @('docker.repository') ~ ':' ~ @('app.version') }}-console as console
LABEL build="{{ @('workspace.name') ~ ':' ~ @('app.version') }}"
RUN if [ -d /app/tools/assets/ ]; then rm -rf /app/tools/assets/; fi
RUN if [ -d {{ @('frontend.path') }}/node_modules/ ]; then rm -rf {{ @('frontend.path') }}/node_modules/; fi
{% endif %}
Expand Down
4 changes: 3 additions & 1 deletion src/_base/harness/config/cleanup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ function('built_images', [services]): |
command('cleanup built-images'):
env:
IMAGES: = built_images(docker_service_images())
BUILD_LABEL: = @('workspace.name') ~ ':' ~ @('app.version')
exec: |
#!bash
IMAGES=($IMAGES)
docker image rm --force -- "${IMAGES[@]}"
run docker image rm --force -- "${IMAGES[@]}"
run "docker images filter=label=build=$(printf '%q' "$BUILD_LABEL") -q | xargs docker image rm --force"

0 comments on commit bf843bc

Please sign in to comment.