-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathwith-builder.sh
executable file
·51 lines (38 loc) · 1.22 KB
/
with-builder.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/bash -eu
# This script takes a command and executes it inside a container created with
# the editor-api:builder image, allowing easy-ish updates to Gemfile.lock and
# yarn.lock.
cmd="$*"
# The image we're working against
image="editor-api:builder"
# Files we copy in to the builder, and then out again. These files are the
# ones in the builder target of the Dockerfile.
files="Gemfile Gemfile.lock"
# Change to the repo root directory.
cd $(dirname $0)/..
function log() {
echo '>>> ' $*
}
# Container inside which we'll make our changes
log "Creating new container from $image"
builder=$(docker create -it $image $cmd)
function cleanup () {
log "Removing $image container"
docker rm -f $builder || true
}
# Ensure our created container is removed on exit
trap cleanup EXIT
log "Copying files to $image container"
for f in $files ; do
docker cp $f $builder:/app/
done
log "Starting $image container"
docker start -ai $builder
# Now the command has run, commit the changes, so that if we run this again,
# we'll start from this point.
log "Committing changes against the $image image"
docker commit $builder $image
log "Copying files back out of the $image container"
for f in $files ; do
docker cp $builder:/app/$f $f
done