Skip to content

Instantly share code, notes, and snippets.

@grayside
Last active February 13, 2017 07:32
Show Gist options
  • Save grayside/cec46c14ed2b408377ea83610cf6d35c to your computer and use it in GitHub Desktop.
Save grayside/cec46c14ed2b408377ea83610cf6d35c to your computer and use it in GitHub Desktop.
Dockerfile for running Phase2 Yeoman generators and capturing the output via a volume mount.
version: "2.1"
services:
# Run the gadget generator.
gadget:
extends: base
entrypoint: [ "yo", "gadget", "--no-insight", "--skip-install" ]
# Run the pattern-label-starter generator.
pls:
extends: base
entrypoint: [ "yo", "pattern-lab-starter", "--no-insight", "--skip-install" ]
# Run the generator-p2 generator. Extends from 'cli' service because we
# cannot install private libraries in the Dockerfile.
p2:
extends: cli
entrypoint: [ "yo", "p2", "--no-insight", "--skip-install" ]
# Run the generator-p2-env generator. Extends from 'cli' service because we
# cannot install private libraries in the Dockerfile.
p2-env:
extends: cli
entrypoint: [ "yo", "p2-env", "--no-insight", "--skip-install" ]
# Run the generator-p2-env generator. Extends from 'cli' service because we
# cannot install private libraries in the Dockerfile.
p2-jenkins:
extends: cli
entrypoint: [ "yo", "p2-env:jenkins", "--no-insight", "--skip-install" ]
# Run the generator-p2-env generator. Extends from 'cli' service because we
# cannot install private libraries in the Dockerfile.
p2-env-test:
extends: cli
entrypoint: "npm test"
working_dir: /usr/local/lib/node_modules/generator-p2-env
# Facilitates development against local clones of the "private" generators.
# The source location of the volume mounts is arbitrary. The destination is
# the global install path for npm inside the container and simulates the
# result of installing properly.
#
# From inside the container you can navigate to the projects in this location
# and run npm install or (from generator-p2) npm link generator-p2-env.
cli:
extends: base
entrypoint: /bin/sh
volumes:
- ./generator-p2:/usr/local/lib/node_modules/generator-p2
- ./generator-p2-env:/usr/local/lib/node_modules/generator-p2-env
# Provides a common baseline of assembling the Docker image and output
# location of the generated code.
#
# All generated output via normal use of this Dockerfile outputs code in
# '~/Projects/newproject', however you can run with YO_PROJECT_DIRECTORY
# environment variable to choose a different location.
base:
build: .
network_mode: "bridge"
volumes:
- ${YO_PROJECT_DIRECTORY:-~/Projects/newproject}:/generated
FROM node:4-alpine
ENV YO_P2_VERSION 2.2.0
ENV PATTERN_LAB_STARTER_VERSION 2.0.0
ENV GADGET_VERSION 1.0.0-rc1
ENV P2_ENV_VERSION 1.2.0
RUN node -v
RUN npm -v
RUN echo "Yeoman Doctor will warn about our npm version being outdated. It is expected and OK."
RUN npm install --global --silent yo
RUN npm install --global --silent generator-gadget@v$GADGET_VERSION
RUN npm install --global --silent generator-pattern-lab-starter@v$PATTERN_LAB_STARTER_VERSION
# These generators remain private and so cannot be installed yet.
# RUN npm install --global --silent git+ssh://bitbucket.org/phase2tech/generator-p2.git#v$YO_P2_VERSION
# RUN npm install --global --silent git+ssh://bitbucket.org/phase2tech/generator-p2-env.git#v$P2_ENV_VERSION
# Add a yeoman user because Yeoman freaks out and runs setuid(501).
# This was because less technical people would run Yeoman as root and cause problems.
# Setting uid to 501 here since it's already a random number being thrown around.
# @see https://github.com/yeoman/yeoman.github.io/issues/282
# @see https://github.com/cthulhu666/docker-yeoman/blob/master/Dockerfile
RUN adduser -D -u 501 yeoman && \
echo "yeoman ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
# Yeoman needs the use of a home directory for caching and certain config storage.
ENV HOME /home/yeoman
RUN mkdir /generated && chown yeoman:yeoman /generated
WORKDIR /generated
# Always run as the yeoman user
USER yeoman
CMD /bin/sh
# Run a Yeoman generator with a command such as:
# docker build -t yeoman .
# docker run -it -v "/Users/username/Projects/newproject:/generated" --rm yeoman yo gadget --no-insight --skip-install
# The --no-insight flag is recommended to avoid prompts for usage collection.
# @see https://github.com/yeoman/yo/issues/20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment