Skip to content

Commit

Permalink
Cache docker images to Google Container Registry (#250)
Browse files Browse the repository at this point in the history
For now, we still rely on logged-in users to manually push a new version
of the image when dependencies change, in the future we should automate
that too. CI and other users can already rely on those images to avoid
rebuilding the images locally every time, since the Registry is set to
allow public access.
  • Loading branch information
tiziano88 authored Oct 7, 2019
1 parent e366a8a commit 18cf4ae
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 3 deletions.
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,23 @@ jobs:
include:
- name: check formatting
script:
- ./scripts/docker_pull
- ./scripts/docker_run ./scripts/check_formatting
- name: build server
script:
- echo "build --show_progress_rate_limit=5.0" >> .bazelrc
- ./scripts/docker_pull
- ./scripts/docker_run ./scripts/build_server
- ./scripts/docker_run ./scripts/build_dev_server
- name: run examples
script:
- echo "build --show_progress_rate_limit=5.0" >> .bazelrc
- ./scripts/docker_pull
- ./scripts/run_examples
- ./scripts/docker_run ./scripts/check_generated
- name: run tests
script:
- echo "build --show_progress_rate_limit=5.0" >> .bazelrc
- ./scripts/docker_pull
- ./scripts/docker_run ./scripts/run_tests
- ./scripts/docker_run ./scripts/check_generated
14 changes: 14 additions & 0 deletions scripts/docker_pull
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash

# This script can be used by anyone, including CI, to pull a version of the image from Google
# Container Registry, which should allow download public downloads.
# See https://pantheon.corp.google.com/gcr/settings?project=oak-ci&folder&organizationId=433637338589

set -o errexit
set -o nounset
set -o xtrace

# See https://pantheon.corp.google.com/gcr/images/oak-ci/GLOBAL/oak
readonly DOCKER_IMAGE_NAME='gcr.io/oak-ci/oak'

docker pull "$DOCKER_IMAGE_NAME:latest"
13 changes: 13 additions & 0 deletions scripts/docker_push
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash

# This script should be used by logged-in users with write access to the Google Container Registry
# to push a new version of the image.

set -o errexit
set -o nounset
set -o xtrace

# See https://pantheon.corp.google.com/gcr/images/oak-ci/GLOBAL/oak
readonly DOCKER_IMAGE_NAME='gcr.io/oak-ci/oak'

docker push "$DOCKER_IMAGE_NAME:latest"
10 changes: 7 additions & 3 deletions scripts/docker_run
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@ readonly DOCKER_UID="${UID:-0}"
readonly DOCKER_GID="${GID:-0}"
readonly DOCKER_USER="${USER:-root}"

# See https://pantheon.corp.google.com/gcr/images/oak-ci/GLOBAL/oak
readonly DOCKER_IMAGE_NAME='gcr.io/oak-ci/oak'

mkdir -p './bazel-cache'
mkdir -p './cargo-cache'

docker build \
--tag=oak \
--cache-from="$DOCKER_IMAGE_NAME:latest" \
--tag="$DOCKER_IMAGE_NAME:latest" \
. 1>&2

docker_run_flags=(
Expand All @@ -42,7 +46,7 @@ docker_run_flags=(

if [[ "$1" == '--detach' ]]; then
docker_run_flags+=('--detach')
docker run "${docker_run_flags[@]}" oak:latest "${@:2}"
docker run "${docker_run_flags[@]}" "$DOCKER_IMAGE_NAME:latest" "${@:2}"
else
docker run "${docker_run_flags[@]}" oak:latest "$@"
docker run "${docker_run_flags[@]}" "$DOCKER_IMAGE_NAME:latest" "$@"
fi

0 comments on commit 18cf4ae

Please sign in to comment.