Last active
September 4, 2019 14:06
-
-
Save Bunk/2294d394e552c3c0024d167a4f2967d9 to your computer and use it in GitHub Desktop.
Docker build pipeline
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
# The dependencies image has all build-dependencies needed for | |
# building the image embedded in it. The reason this is a separate | |
# image is so that it can be built, cached, and re-used across | |
# both the developer and production image builds. | |
FROM node:10.16.3-alpine | |
WORKDIR /var/app | |
# NOTE: There's no reason to later remove these since the production | |
# image will start from a different base image without them installed. | |
RUN apk --update add --no-cache make g++ git | |
COPY package.json yarn.lock ./ | |
RUN yarn |
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
# The developer image has all app code necessary to build | |
# AND run the application. This should also include any | |
# IDE-specific dependencies that could be useful during development. | |
FROM app-deps:local | |
WORKDIR /var/app | |
COPY . . | |
CMD ["node","app.js"] |
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
# Stage 0 - Start with the developer build | |
# Remove all non-production NPM modules to reduce image size | |
FROM app:dev as dev | |
RUN yarn --production | |
# Stage 1 - Create the final production image | |
# Only copy the necessary source files over from the dev image. | |
# Since we're starting from a fresh Node image, we don't have | |
# any of the non-essential Alpine build dependencies available anymore. | |
# | |
# Thankfully, this no longer matters since our build steps are already | |
# completed and we no longer need any bloated build dependencies. | |
FROM node:10.16.3-alpine | |
WORKDIR /var/app | |
# Copy production app files over | |
COPY --from=dev /var/app/node_modules ./node_modules | |
COPY --from=dev /var/app/lib ./lib | |
COPY --from=dev /var/app/app.js ./app.js | |
CMD ["node","app.js"] |
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
.PHONY: help | |
help: ## This help | |
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST) | |
build: build-dev build-prod ## Build all app images | |
build-deps: | |
docker build -t app-deps:local -f ./Dockerfile-deps.dockerfile . | |
build-dev: build-deps ## Build the development image | |
docker build -t app:dev -f ./Dockerfile-dev.dockerfile . | |
build-prod: build-dev ## Build the production app image | |
docker build -t app:latest -f ./Dockerfile . |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment