-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
51 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 |