To create a new versioner image, after updating one or more of the microservice images (eg runner, web, start-points-base, etc), simply:
./sh/refresh-env/sh
git add .
git commit -m "[RELEASE=0.1.397] Patch level updates"
(assuming 0.1.396 was the current latest)git push
The entrypoint
for a cyberdojo/versioner
docker image simply prints a
self-consistent, working set of image-name, commit-sha, image-tag, and port-number, environment variables.
For example:
$ docker run --rm cyberdojo/versioner:0.1.89 ... CYBER_DOJO_RUNNER_IMAGE=cyberdojo/runner CYBER_DOJO_RUNNER_SHA=a74c5bcbb43e8fcf497be997809ce1951979e7a0 CYBER_DOJO_RUNNER_TAG=a74c5bc CYBER_DOJO_RUNNER_PORT=4597 ... CYBER_DOJO_WEB_IMAGE=cyberdojo/web CYBER_DOJO_WEB_SHA=333d9be4f64d3950c0bc5a0c450ce892b10e8389 CYBER_DOJO_WEB_TAG=333d9be CYBER_DOJO_WEB_PORT=3000 ...
The main cyber-dojo bash script uses these environment variables to:
- control the START_POINTS_BASE identity when running
cyber-dojo start-point create ...
- control the image identity and port number of the cyber-dojo microservice containers.
For example, suppose cyberdojo/versioner:latest
is a tag for cyberdojo/versioner:0.1.89
(which we can see a fragment of above), and we bring up a cyber-dojo server:
$ cyber-dojo up Using version=0.1.89 (public) ... Using runner=cyberdojo/runner:a74c5bc Using web=cyberdojo/web:333d9be ...
- Note the runner service identity is
${CYBER_DOJO_RUNNER_IMAGE}:${CYBER_DOJO_RUNNER_TAG}
- Note the web service identity is
${CYBER_DOJO_WEB_IMAGE}:${CYBER_DOJO_WEB_TAG}
- The TAG is always the first seven chars of the SHA.
- This is because you cannot (at the time of writing) use the bash-style
${VAR:0:7}
syntax in a docker-compose.yml file so the TAG has to be in its own environment variable.
Integration tests can export
these environment variables, and use them
in a docker-compose.yml
file to bring up dependent services.
For example:
#!/usr/bin/env bash
set -Eeu
echo_versioner_env_vars() { docker run --rm cyberdojo/versioner:latest; }
export $(echo_versioner_env_vars)
docker compose --file my-docker-compose.yml up --detach
# ...wait for all services to be ready
# ...run your tests which depend on, eg, runner...
#
# my-docker-compose.yml
services:
runner:
image: ${CYBER_DOJO_RUNNER_IMAGE}:${CYBER_DOJO_RUNNER_TAG}
...
If you are working on cyber-dojo, from source, and you want to run a cyber-dojo server which uses your locally built image(s) one option is to explicitly replace specific environment variables. For example:
#!/usr/bin/env bash
set -Eeu
echo_versioner_env_vars()
{
# Echoes all current service env-vars. See above.
docker run --rm cyberdojo/versioner:latest
# Now override specific env-vars for local work-in-progress
echo CYBER_DOJO_RUNNER_SHA=c93a9c650a8c4e7cc83545ce3f9108c2c76746d8
echo CYBER_DOJO_RUNNER_TAG=c93a9c6
#
echo CYBER_DOJO_SAVER_SHA=13b14d947fa9e873820d3e4a1e2f593735e9410a
echo CYBER_DOJO_SAVER_TAG=13b14d9
# ...
}
# Now export all echoed env-vars
export $(echo_versioner_env_vars)
Alternatively you can build a cyberdojo/versioner:latest
fake image
which prints SHA/TAG values for your locally built image(s).
For example, if you are working on a local web
service, you could
- create a fake
cyberdojo/versioner:latest
which printsCYBER_DOJO_WEB_SHA
andCYBER_DOJO_WEB_TAG
values matching the git-sha forcyberdojo/web:TAG
image built from your localweb
git repo (onmaster
atHEAD
). - reissue the
cyber-dojo up ...
command.
You can automate creating a fake cyberdojo/versioner:latest
using this bash script:
#!/usr/bin/env bash
set -Eeu
# Builds a fake cyberdojo/versioner:latest image that serves
# CYBER_DOJO_WEB SHA/TAG values for a local web image
# whose repo's dir/ contains this script.
readonly ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
readonly TMP_DIR="$(mktemp -d /tmp/XXXXXXX)"
remove_TMP_DIR() { rm -rf "${TMP_DIR} > /dev/null"; }
trap remove_TMP_DIR INT EXIT
echo_versioner_env_vars() { docker run --rm cyberdojo/versioner:latest; }
# - - - - - - - - - - - - - - - - - - - - - - - -
build_fake_versioner_with_sha_and_tag_for_local_web()
{
local -r sha_var_name=CYBER_DOJO_WEB_SHA
local -r tag_var_name=CYBER_DOJO_WEB_TAG
local -r fake_sha="$(git_commit_sha)"
local -r fake_tag="${fake_sha:0:7}"
local env_vars="$(echo_versioner_env_vars)"
env_vars=$(replace_with "${env_vars}" "${sha_var_name}" "${fake_sha}")
env_vars=$(replace_with "${env_vars}" "${tag_var_name}" "${fake_tag}")
echo "${env_vars}" > ${TMP_DIR}/.env
local -r fake_image=cyberdojo/versioner:latest
{
echo 'FROM alpine:latest'
echo 'COPY . /app'
echo 'ARG SHA'
echo 'ENV SHA=${SHA}'
echo 'ARG RELEASE'
echo 'ENV RELEASE=${RELEASE}'
echo 'ENTRYPOINT [ "cat", "/app/.env" ]'
} > ${TMP_DIR}/Dockerfile
docker build \
--build-arg SHA="${fake_sha}" \
--build-arg RELEASE=999.999.999 \
--tag "${fake_image}" \
"${TMP_DIR}"
}
# - - - - - - - - - - - - - - - - - - - - - - - -
replace_with()
{
local -r env_vars="${1}"
local -r name="${2}"
local -r fake_value="${3}"
local -r all_except=$(echo "${env_vars}" | grep --invert-match "${name}")
printf "${all_except}\n${name}=${fake_value}\n"
}
# - - - - - - - - - - - - - - - - - - - - - - - -
git_commit_sha()
{
# eg 3240bfbcf3f02a9625e1ce55d054126c1a1c2cf1
git rev-parse HEAD
}
# - - - - - - - - - - - - - - - - - - - - - - - -
build_fake_versioner_with_sha_and_tag_for_local_web
Alternatively, you can hand edit the SHA (git rev-parse HEAD
) and TAG values
into versioner/app/.env
and then build a local cyberdojo/versioner:latest
image.
$ cd versioner
$ ./build_test_publish.sh --build-only