Skip to content

Instantly share code, notes, and snippets.

@AlexAtkinson
Last active November 30, 2023 13:46
Show Gist options
  • Save AlexAtkinson/1cd0323af90640c9b0e705b04e7e0a05 to your computer and use it in GitHub Desktop.
Save AlexAtkinson/1cd0323af90640c9b0e705b04e7e0a05 to your computer and use it in GitHub Desktop.
Docker Example: Building Artifacts
# DOCKER EXAMPLE: Generate assets with a docker build
# 1. Create this Dockerfile
# 2. Run: `docker build --output=foo --target=assets .`
#
# This results in an asset being created and exported to the
# local path foo/ on the host os. The key here is using
# 'scratch' to ensure an empty contianer the assets can be
# copied into before being exported. (Otherwise you get the
# entire OS.)
#
# REF: https://hub.docker.com/_/scratch/
# STEP ONE: Use some image as the BUILDER or SOURCE
# The point here is that this is where the asset
# comes from.
FROM debian:bookworm-slim as builder
# The location of your desired assets in the source image.
WORKDIR /src
# Creating an example asset. But this might be a batch of
# angular files, as a random example. You could even zip
# them here.
RUN touch foo
# STEP TWO: Use the scratch image to isolate the desired
# asset so that they can be exported.
FROM scratch AS assets
# Copy the asset(s) from the builder/source into scratch.
COPY --from=builder /src/foo /
ENTRYPOINT [ "/src" ]
# STEP THREE: Run a build cmd with the --output flag, like:
# `docker build --output=foo --target=assets .`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment