Continuous Integration scripts
npm install @trussle/ciThis package provides a suite of scripts used by Trussle's Continuous
Integration system to build Docker images for testing and deployment.
Install this package as a devDependency:
``sh`
npm install --save-dev @trussle/ci
Next, set up your Dockerfile with the following constraints:
- There should be a builder stage, which creates an image ready to build and/builder
test in the directory. The ENTRYPOINT should run all _unit_ tests/builder/test-results
(with coverage) and provide results in JUnit format to the directory
.ENTRYPOINT
- The final stage of the Dockerfile should create a runner image continaing only
the files required to run the application. The should run theNPM_TOKEN
application.
- The host machine's NPM token will be injected into the image as the argument
, so you'll likely need the following lines at the top of your
Dockerfile:
`docker`Embed the NPM_TOKEN (passed in from the host machine) into the image.
ARG NPM_TOKEN
RUN echo -n ${NPM_TOKEN} > /root/.npmrc
Samples of Dockerfiles can be found in the templates.
If you have integration tests (tests that require an external dependency to be
running), you should include a Docker Compose file that looks like this:
`yml
version: "2.1"
services:
integration:
image: "878732450721.dkr.ecr.eu-west-1.amazonaws.com/[package-name]-builder:latest"
# depends_on:
# - service1
# - service2
entrypoint: npm run test:integration
environment:
- NODE_ENV=CI
# Your other services go here!
`
You can now run:
- npx t-ci builder to make the build/test image.npx t-ci test-unit
- runs unit tests in the builder.npx t-ci test-integration
- sets up the Docker Compose environment and runsnpx t-ci runner
the integration tests.
- to make the runner image.
These commands can be used to make your Jenkinsfile super short:
`groovy``
pipeline {
agent any
stages {
stage("Setup") { steps { sh "npx t-ci builder" } }
stage("Tests") {
parallel {
stage("Unit Tests") { steps { sh "npx t-ci test-unit" } }
stage("Integration Tests") { steps { sh "npx t-ci test-integration" } }
}
}
stage("Build") { steps { sh "npx t-ci runner" } }
}
post {
always {
junit "test-results/*/.xml"
sh "aws s3 sync test-results/ s3://qa-junit-test-reports/${env.JOB_NAME}/${env.BUILD_NUMBER}/test-results"
cleanWs(
cleanWhenAborted: true,
cleanWhenFailure: true,
cleanWhenNotBuilt: true,
cleanWhenSuccess: true,
cleanWhenUnstable: true,
cleanupMatrixParent: true,
deleteDirs: true
)
}
}
}