This repository contains build steps for building and deploying a docker container which mainly provides:
- Build tooling for Node projects
- NVM for selecting and installing arbitrary versions of Node
- Yarn as an alternative to NPM
Branch | Status |
---|---|
Master | |
Develop |
docker run keymux/docker-ubuntu-nvm-yarn /nvm.sh node -e "console.log('Hello World');"
FROM keymux/docker-ubuntu-nvm-yarn:0.2.0
# Add your magic here
Using Jenkins, you can target the Jenkinsfile
to automate building. Some dependencies for Jenkins:
- Credentials:
jenkins_github_https
should hold a username and password for github:- For removing the anonymous limitation on github API hits
jenkins_github_access_token
must hold an API key for the github HTTPS API:- For posting github comments to PRs
jenkins_github_ssh
must hold a private key which can be used to authenticate with github over SSH:- For pushing tags
- For merging any new code changes on master into develop when necessary
jenkins_docker_keymux_login
must hold a username and password to docker hub which permits modifications to the keymux/ namespace- For pushing docker images to docker hub
- You must have one or more build nodes which have docker installed
- For each of those nodes:
- the user that Jenkins will use on that box must have access to the docker daemon
- Only the docker socket (
/var/run/docker.sock
) is supported - x64 is required (because of
/usr/lib/x86_64-linux-gnu/libltdl.so.7
). Probably other related impacts here, too. - The jenkins user must be
1001
, see-u 1001:999
in Jenkinsfile andENV USERID 1001
in Dockerfile - The docker user group must be
999
, see:-u 1001:999
in Jenkinsfile andENV DOCKERGID 999
in Dockerfile
You can do a number of different pipeline-based jobs here, but I'll only touch on the github Organization job.
-
Projects
- Credentials:
jenkins_github_https
- This is optional, but highly recommended for performance
- Owner:
keymux
(or whomever) - Behaviours
- Discover Branches
- Strategy:
Exclude branches that are also filed as PRs
- Strategy:
- Discover pull requests from origin
- Strategy:
Merging the pull request with the current target branch revision
- Strategy:
- Discover pull requests from forks
- Strategy:
Merging the pull request with the current target branch revision
- Trust:
Nobody
(recommended because attackers could use your settings here to compromise your Jenkins server and/or nodes)
- Strategy:
- Discover Branches
- Advanced clone behaviours (Have to add this)
- Fetch tags:
true
- Fetch tags:
- Checkout over SSH (Have to add this)
- Credentials:
jenkins_github_ssh
- Credentials:
- Credentials:
-
Project Recognizers
- Pipeline Jenkinsfile
- Script Path:
Jenkinsfile
- Script Path:
- Pipeline Jenkinsfile
-
Scan Organization Triggers
- Periodically if not otherwise run:
true
- Interval:
1 hour
(or whatever)
- Interval:
- Periodically if not otherwise run:
-
Orphaned Item Strategy
- Discard old items:
true
- Discard old items:
You should have a working pipeline.
yarn install
to pull dependencies, which are required for many steps.
These two commands are identical:
yarn build
scripts/build.sh
Let's say I want to just print Hello World. (yarn start
and scripts/start.sh
may be used interchangeably here)
yarn start echo Hello World
Now what if I want to spin up a docker container inside that container?
WARNING: This will pull down the hello-world
container from docker hub.
yarn start docker run hello-world
yarn test:unit
yarn test:e2e
yarn test:version 6.10.2
yarn report:_all
yarn report:aggregate
yarn preview:comment
rm -rf reports && yarn report:_all && yarn report:aggregate && yarn preview:comment
Report Name | Command |
---|---|
deploy | yarn test:deploy |
unit | yarn test:unit |
coverage | yarn test:coverage |
Deploy is an odd one since it expects certain environment variables.
# Be sure to set package.json's .version field to 0.1.0 first
CHANGE_BRANCH=release/v0.1.0 CHANGE_TARGET=master yarn report:deploy
# or add OVERRIDE_VERSION_CHECK=0.1.0
CHANGE_BRANCH=release/v0.1.0 CHANGE_TARGET=master OVERRIDE_VERSION_CHECK=0.1.0 yarn report:deploy
# Be sure to set package.json's .version field to 999.999.999 first
CHANGE_BRANCH=release/v999.999.999 CHANGE_TARGET=master yarn report:deploy
# or add OVERRIDE_VERSION_CHECK=999.999.999
CHANGE_BRANCH=release/v999.999.999 CHANGE_TARGET=master OVERRIDE_VERSION_CHECK=999.999.999 yarn report:deploy
yarn push