Created
June 21, 2017 22:53
-
-
Save chendrix/97325a7dc2a9e6531adf14b3be38e895 to your computer and use it in GitHub Desktop.
How to use docker-image-resource to build custom docker images used as inputs for later tasks
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
jobs: | |
- name: build-and-test | |
plan: | |
- task: build-image | |
privileged: true | |
config: | |
platform: linux | |
image_resource: | |
type: docker-image | |
source: | |
repository: concourse/docker-image-resource | |
outputs: | |
- name: image-output | |
params: | |
DESTINATION: image-output | |
WORKSPACE: /tmp/scratch | |
run: | |
path: /bin/bash | |
args: | |
- -c | |
- | | |
set -eux | |
## Need this, but depends on internals of docker-image-resource | |
## maybe can be replaced with your own scripts to start_docker | |
source /opt/resource/common.sh | |
start_docker "[]" "" | |
## This should be done via inputs | |
mkdir -p "${WORKSPACE}/git-master" | |
cat << EOF > "${WORKSPACE}/git-master/package.json" | |
{ | |
"name": "node-js-sample", | |
"version": "0.2.0", | |
"description": "A sample Node.js app using Express 4", | |
"main": "index.js", | |
"scripts": { | |
"start": "node index.js" | |
}, | |
"dependencies": { | |
"express": "^4.13.3" | |
}, | |
"engines": { | |
"node": "4.0.0" | |
}, | |
"repository": { | |
"type": "git", | |
"url": "https://github.com/heroku/node-js-sample" | |
}, | |
"keywords": [ | |
"node", | |
"heroku", | |
"express" | |
], | |
"author": "Mark Pundsack", | |
"contributors": [ | |
"Zeke Sikelianos <zeke@sikelianos.com> (http://zeke.sikelianos.com)" | |
], | |
"license": "MIT" | |
} | |
EOF | |
cat << EOF > "${WORKSPACE}/Dockerfile" | |
FROM node:8.1.2-alpine | |
ADD git-master /tmp/git-master | |
RUN (cd /tmp/git-master && npm install) | |
RUN mv /tmp/git-master/node_modules . | |
EOF | |
## The meat of what you are doing | |
docker build -t test "${WORKSPACE}" | |
docker run \ | |
--cidfile=/tmp/container.cid \ | |
-v /opt/resource/print-metadata:/tmp/print-metadata \ | |
--entrypoint /tmp/print-metadata \ | |
test > "${DESTINATION}/metadata.json" | |
mkdir -p "${DESTINATION}/rootfs/" | |
docker export $(cat /tmp/container.cid) | tar --exclude="dev/*" -xf - -C "${DESTINATION}/rootfs/" | |
- task: check-if-it-worked | |
image: image-output | |
config: | |
platform: linux | |
run: | |
path: echo | |
args: | |
- /tmp/git-master/package.json |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hmm, NPM doesn't seem to work in the exported image:
Testing
npm --version
with the image directly:Testing
npm --version
with the exported image: