Skip to content

Commit

Permalink
ci(.ciecleci, scripts): tag docker images
Browse files Browse the repository at this point in the history
Signed-off-by: Taiga Nakayama <dora@dora-gt.jp>
  • Loading branch information
dora-gt committed Nov 13, 2019
1 parent 7a80776 commit bddd7d9
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 19 deletions.
2 changes: 1 addition & 1 deletion docker/CI/README.md → .circleci/README.md
Expand Up @@ -14,7 +14,7 @@ So we need new docker images of:
- ilp-node
- ilp-cli

In order to build new docker images, we build the source code once like `cargo build --bin ilp-node --bin ilp-cli`, not twice because we want to reduce compilation time. After the build, we just copy the binaries to docker containers using `CI/node.dockerimage` and `CI/ilp-cli.dockerimage`. That is why we don't use normal `node.dockerfile` and `ilp-cli.dockerfile`. It compiles the source files of `interledger-rs` **inside** the container, so we need **two** compilation of the source although that seems natural for normal uses.
In order to build new docker images, we build the source code once like `cargo build --bin ilp-node --bin ilp-cli`, not twice because we want to reduce compilation time. After the build, we just copy the binaries to docker containers using `.circleci/node.dockerimage` and `.circleci/ilp-cli.dockerimage`. That is why we don't use normal `node.dockerfile` and `ilp-cli.dockerfile`. It compiles the source files of `interledger-rs` **inside** the container, so we need **two** compilation of the source although that seems natural for normal uses.

The docker images `node.dockerfile` and `ilp-cli.dockerfile` contain platform-agnostic (although it is not completely agnostic) binaries which means it does not rely on dynamic libraries and uses `musl` instead. So we have to provide `musl` environment for `Cargo`. That is why `circleci-rust-dind.dockerfile` contains `musl`.

Expand Down
Expand Up @@ -11,7 +11,7 @@ RUN echo "deb http://security.ubuntu.com/ubuntu xenial-security main" | tee -a /
apt-get install libcurl3 -y && \
# get libcurl to a place where it won't get overwritten
cp /usr/lib/x86_64-linux-gnu/libcurl.so.3 /usr/lib && \
apt-get install curl -y
apt-get install curl jq -y

# Because nc command doesn't accept -k argument correctly, we need to install ncat of buster.
RUN echo "deb http://deb.debian.org/debian/ buster main contrib non-free" >> /etc/apt/sources.list && \
Expand Down
58 changes: 47 additions & 11 deletions .circleci/config.yml
Expand Up @@ -83,9 +83,15 @@ jobs:
docker_layer_caching: true
- checkout
# If something wrong is cached, use these lines
#- run:
# name: Clear docker cache
# command: docker images --no-trunc --format '{{.ID}}' interledgerrs/settlement-engines | xargs --no-run-if-empty docker rmi
# - run:
# name: Clear docker cache
# command: docker images --no-trunc --format '{{.ID}}' interledgerrs/settlement-engines | xargs --no-run-if-empty docker rmi
- run:
# Although we use `docker_layer_caching`, we need to pull these latest images
name: Pull Docker Images
command: |
docker pull interledgerrs/settlement-engines:latest
docker pull interledgerjs/settlement-xrp:latest
- restore_cache:
keys:
- cargo-cache-2-{{ checksum "Cargo.lock" }}-{{ .Branch }}
Expand Down Expand Up @@ -136,16 +142,35 @@ jobs:
- run:
# builds release profile images to be released
name: Build docker images
command: docker/docker-build.sh node ilp-cli
command: |
if [ "${CIRCLE_BRANCH}" = "master" ] || [[ "${CIRCLE_TAG}" =~ ^ilp-node- ]]; then
export DOCKER_IMAGE_TAG=$(./.circleci/get_docker_image_tag.sh ilp-node ${CIRCLE_TAG})
docker/docker-build.sh node testnet-bundle
fi
if [ "${CIRCLE_BRANCH}" = "master" ] || [[ "${CIRCLE_TAG}" =~ ^ilp-cli- ]]; then
export DOCKER_IMAGE_TAG=$(./.circleci/get_docker_image_tag.sh ilp-cli ${CIRCLE_TAG})
docker/docker-build.sh ilp-cli
fi
environment:
PROFILE: "release"
- run:
name: Push to DockerHub
# TODO tag properly
command: |
echo $DOCKER_PASS | docker login -u $DOCKER_USER --password-stdin
docker push interledgerrs/node:latest
docker push interledgerrs/ilp-cli:latest
if [ "${CIRCLE_BRANCH}" = "master" ] || [[ "${CIRCLE_TAG}" =~ ^ilp-node- ]]; then
DOCKER_IMAGE_TAG=$(./.circleci/get_docker_image_tag.sh ilp-node ${CIRCLE_TAG})
echo "Pushing docker image of tag: interledgerrs/node:${DOCKER_IMAGE_TAG}"
docker push interledgerrs/node:${DOCKER_IMAGE_TAG}
docker push interledgerrs/testnet-bundle:${DOCKER_IMAGE_TAG}
fi
if [ "${CIRCLE_BRANCH}" = "master" ] || [[ "${CIRCLE_TAG}" =~ ^ilp-cli- ]]; then
DOCKER_IMAGE_TAG=$(./.circleci/get_docker_image_tag.sh ilp-cli ${CIRCLE_TAG})
echo "Pushing docker image of tag: interledgerrs/ilp-cli:${DOCKER_IMAGE_TAG}"
docker push interledgerrs/ilp-cli:${DOCKER_IMAGE_TAG}
fi
- save_cache:
key: cargo-cache-2-{{ checksum "Cargo.lock" }}-{{ .Branch }}
paths:
Expand All @@ -155,13 +180,24 @@ workflows:
version: 2
build_and_test-md:
jobs:
- build
- test-md
- update-docker-images: # updates docker images on DockerHub, only if the branch is master
- build:
filters:
tags:
only: # we need this to kick builds when tags are given
- /.*/
- test-md:
filters:
tags:
only: # we need this to kick builds when tags are given
- /.*/
- update-docker-images: # updates docker images on DockerHub, only if the branch is master or something is tagged
filters:
branches:
only:
only: # master branch will be tagged as `latest` image
- master
tags:
only: # whatever tagged binary crates
- /^(ilp-node-|ilp-cli-).*$/
requires:
- build
- test-md
23 changes: 23 additions & 0 deletions .circleci/get_docker_image_tag.sh
@@ -0,0 +1,23 @@
#!/usr/bin/env bash

# Returns `latest` or crate version. If git_tag ($2) argument is given, it is considered as that the new version
# is published. If the tag is the form of semantic version like "ilp-node-0.4.1-beta.3", this script returns
# the version of crate like "0.4.1-beta.3" because tag names generated by `cargo release` look a bit redundant.
# If the tag is not one of semantic version, just returns the tag itself and the docker image will be tagged
# with the git tag.
# If no tag is given, it is considered as a `latest` (or possibly could be said `nightly`) build.
# This script requires `jq`

crate_name=$1
git_tag=$2

if [ -n "$git_tag" ]; then
# If it is a tag of semantic version expression
if [[ "$git_tag" =~ ^.*v([0-9]+)\.([0-9]+)\.([0-9]+)(-([0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*))?(\+[0-9A-Za-z-]+)?$ ]] ; then
cargo read-manifest --manifest-path crates/${crate_name}/Cargo.toml | jq -r .version
else
printf "$git_tag"
fi
else
printf "latest"
fi
File renamed without changes.
File renamed without changes
File renamed without changes.
15 changes: 9 additions & 6 deletions docker/docker-build.sh
@@ -1,6 +1,7 @@
#!/bin/bash

# intended to be run in the top directory
docker_image_tag=${DOCKER_IMAGE_TAG:-latest}

build_targets=()

Expand All @@ -25,16 +26,18 @@ fi
# if arguments are given, add it as build targets
build_targets+=($@)

printf "\e[32;1mBuilding docker image with tag: ${docker_image_tag}\e[m\n"

for build_target in "${build_targets[@]}"; do
case $build_target in
"ilp-cli") docker build -f ./docker/ilp-cli.dockerfile -t interledgerrs/ilp-cli:latest . ;;
"node") docker build -f ./docker/node.dockerfile -t interledgerrs/node:latest \
"ilp-cli") docker build -f ./docker/ilp-cli.dockerfile -t interledgerrs/ilp-cli:${docker_image_tag} . ;;
"node") docker build -f ./docker/node.dockerfile -t interledgerrs/node:${docker_image_tag} \
--build-arg CARGO_BUILD_OPTION="${CARGO_BUILD_OPTION}" \
--build-arg RUST_BIN_DIR_NAME="${RUST_BIN_DIR_NAME}" \
. ;;
"testnet-bundle") docker build -f ./docker/Dockerfile -t interledgerrs/testnet-bundle:latest . ;;
"circleci-rust-dind") docker build -f ./docker/CI/circleci-rust-dind.dockerfile -t interledgerrs/circleci-rust-dind:latest . ;;
"ci-node") docker build -f ./docker/CI/node.dockerfile -t interledgerrs/node:latest . ;;
"ci-ilp-cli") docker build -f ./docker/CI/ilp-cli.dockerfile -t interledgerrs/ilp-cli:latest . ;;
"testnet-bundle") docker build -f ./docker/Dockerfile -t interledgerrs/testnet-bundle:${docker_image_tag} . ;;
"circleci-rust-dind") docker build -f ./.circleci/circleci-rust-dind.dockerfile -t interledgerrs/circleci-rust-dind:${docker_image_tag} . ;;
"ci-node") docker build -f ./.circleci/node.dockerfile -t interledgerrs/node:${docker_image_tag} . ;;
"ci-ilp-cli") docker build -f ./.circleci/ilp-cli.dockerfile -t interledgerrs/ilp-cli:${docker_image_tag} . ;;
esac
done

0 comments on commit bddd7d9

Please sign in to comment.