Created
March 9, 2023 01:02
-
-
Save dlants/cb9c2dcd9cafee929cc4706c1bc5eb5d to your computer and use it in GitHub Desktop.
yarn in docker build dockerfile w/ private github repo & cache mount
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
# for yarn berry | |
FROM --platform=linux/amd64 node:14.21-bullseye | |
# install node_module packages needed to build | |
WORKDIR /app | |
COPY .yarnrc.yml . | |
COPY .yarn/releases/yarn-3.4.1.cjs .yarn/releases/yarn-3.4.1.cjs | |
COPY package.json . | |
COPY yarn.lock . | |
# local deps & preinstall scripts must be in place before running yarn install | |
# COPY local packages, scripts | |
# the app/.yarn/cache directory will be preserved between builds, to take advantage of the yarn cache. | |
# the --mount=type=ssh flag allows this command to use $SSH_AUTH_SOCKET provided by the docker build command (see below) | |
# yarn asks git to check out the code for the private repo. git, in turn, sshes into github. | |
# Since the docker container is a new host, there are no known_hosts, so by default, ssh will try and confirm the new host | |
# by opening a tty. This will fail. | |
# We remove the need for this confirmation by telling git to run ssh with the StrictHostKeyChecking=no flag. | |
RUN --mount=type=ssh,required=true \ | |
--mount=type=cache,id=yarn,target=/app/.yarn/cache \ | |
GIT_SSH_COMMAND="ssh -o StrictHostKeyChecking=no" yarn install |
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
#!/bin/bash | |
echo $SSH_AUTH_SOCK # should print out something to confirm ssh-agent is running | |
docker build --ssh default . |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment