Skip to content

Commit

Permalink
latest
Browse files Browse the repository at this point in the history
Signed-off-by: Adrian Cole <[email protected]>
  • Loading branch information
Adrian Cole committed Dec 5, 2023
1 parent 3f39737 commit c565a98
Show file tree
Hide file tree
Showing 12 changed files with 92 additions and 175 deletions.
14 changes: 5 additions & 9 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,18 @@ name: deploy
# See https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-syntax-for-github-actions#filter-pattern-cheat-sheet
on:
push:
tags: '[0-9]+.[0-9]+.[0-9]+**' # Ex. 8.272.10 or 15.0.1_p9
tags: '[0-9]+.[0-9]+.[0-9]+**' # Ex. 8.272.10 or 21.0.1_p12

jobs:
deploy:
runs-on: ubuntu-20.04 # newest available distribution, aka focal
runs-on: ubuntu-22.04 # newest available distribution, aka jellyfish
steps:
- name: Checkout Repository
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
fetch-depth: 1 # only needed to get the sha label
- name: Cache Docker
uses: actions/cache@v2
with:
path: ~/.docker
key: ${{ runner.os }}-docker-${{ hashFiles('**/Dockerfile') }}
restore-keys: ${{ runner.os }}-docker
# We can't cache Docker without using buildx because GH actions restricts /var/lib/docker
# That's ok because DOCKER_PARENT_IMAGE is always ghcr.io and local anyway.
- name: Deploy
env:
# GH_USER=<user that created GH_TOKEN>
Expand Down
10 changes: 2 additions & 8 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,11 @@ on:

jobs:
test:
runs-on: ubuntu-20.04 # newest available distribution, aka focal
runs-on: ubuntu-22.04 # newest available distribution, aka jellyfish
steps:
- name: Checkout Repository
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
fetch-depth: 1 # only needed to get the sha label
- name: Cache Docker
uses: actions/cache@v2
with:
path: ~/.docker
key: ${{ runner.os }}-docker-${{ hashFiles('**/Dockerfile') }}
restore-keys: ${{ runner.os }}-docker
- name: Test
run: build-bin/configure_test && build-bin/test
8 changes: 4 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# docker_parent_image is the base layer of full and jre image
#
# Use latest version here: https://github.com/orgs/openzipkin/packages/container/package/alpine
ARG docker_parent_image=ghcr.io/openzipkin/alpine:3.12.1
ARG docker_parent_image=ghcr.io/openzipkin/alpine:3.18.5

# We copy files from the context into a scratch container first to avoid a problem where docker and
# docker-compose don't share layer hashes https://github.com/docker/compose/issues/883 normally.
Expand All @@ -24,7 +24,7 @@ FROM $docker_parent_image as base
# * Use current version from https://pkgs.alpinelinux.org/packages?name=openjdk8
# This is defined in many places because Docker has no "env" script functionality unless you use
# docker-compose: When updating, update everywhere.
ARG java_version=8.272.10
ARG java_version=8.392.08
ARG java_home=/usr/lib/jvm/java-1.8-openjdk
LABEL java-version=$java_version
LABEL java-home=$java_home
Expand All @@ -41,8 +41,8 @@ ENTRYPOINT ["java", "-jar"]
# The JDK image includes a few build utilities and Maven
FROM base as jdk
LABEL org.opencontainers.image.description="OpenJDK on Alpine Linux"
ARG java_version=8.272.10
ARG maven_version=3.6.3
ARG java_version=8.392.08
ARG maven_version=3.9.6
LABEL maven-version=$maven_version

COPY --from=code /code/install.sh .
Expand Down
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,27 @@ This is an internal base layer primarily used in [zipkin](https://github.com/ope

To try the image, run the `java -version` command:
```bash
docker run --rm ghcr.io/openzipkin/java:8.272.10 -version
openjdk version "1.8.0_272"
OpenJDK Runtime Environment (IcedTea 3.17.0) (Alpine 8.272.10-r2)
OpenJDK 64-Bit Server VM (build 25.272-b10, mixed mode)
docker run --rm ghcr.io/openzipkin/java:8.392.08 -version
openjdk version "1.8.0_392"
OpenJDK Runtime Environment (IcedTea 3.29.0) (Alpine 8.392.08-r1)
OpenJDK 64-Bit Server VM (build 25.392-b08, mixed mode)
```

## Release process
Build the `Dockerfile` using the current version without the revision classifier from here:
* https://pkgs.alpinelinux.org/packages?name=openjdk8
```bash
# Note 8.272.10 not 8.272.10-r2!
./build-bin/build 8.272.10
# Note 8.392.08 not 8.392.08-r1!
./build-bin/build 8.392.08
```

Next, verify the built image matches that version:
```bash
docker run --rm openzipkin/java:test -version
openjdk version "1.8.0_272"
OpenJDK Runtime Environment (IcedTea 3.17.0) (Alpine 8.272.10-r2)
OpenJDK 64-Bit Server VM (build 25.272-b10, mixed mode)
openjdk version "1.8.0_392"
OpenJDK Runtime Environment (IcedTea 3.29.0) (Alpine 8.392.08-r1)
OpenJDK 64-Bit Server VM (build 25.392-b08, mixed mode)
```

To release the image, push a tag matching the arg to `build-bin/build` (ex `8.272.10`).
To release the image, push a tag matching the arg to `build-bin/build` (ex `8.392.08`).
This triggers a [GitHub Actions](https://github.com/openzipkin/docker-java/actions) job to push the image.
106 changes: 8 additions & 98 deletions build-bin/README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# Test and Deploy scripts

This is a Docker project, which uses standard conventions for test and deploy. What's notable about
docker-java is that the base layers are only pushed to `ghcr.io`, and tests are simply running the
`-version` command. There's a non-standard `build` script referenced in [../README.md] that allows
easier manual builds of the Dockerfile.
docker-alpine is that the base layers are only pushed to `ghcr.io`, and tests are simply running the
`cat /etc/alpine-release`. There's a non-standard `build` script referenced in [../README.md] that
allows easier manual builds of the Dockerfile.

[//]: # (Below here should be standard for all projects)

## Build Overview
`build-bin` holds portable scripts used in CI to test and deploy the project.

The scripts here are portable. They do not include any CI provider-specific logic or ENV variables.
This helps `.travis.yml` and `test.yml` (GitHub Actions) contain nearly the same contents, even if
This helps `test.yml` (GitHub Actions) and alternatives contain nearly the same contents, even if
certain OpenZipkin projects need slight adjustments here. Portability has proven necessary, as
OpenZipkin has had to transition CI providers many times due to feature and quota constraints.

Expand Down Expand Up @@ -64,7 +64,7 @@ jobs:
test:
steps:
- name: Checkout Repository
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
fetch-depth: 0 # full git history for license check
- name: Test
Expand All @@ -73,49 +73,6 @@ jobs:
build-bin/test
```
### Example Travis setup
`.travis.yml` is a monolithic configuration file broken into stages, of which the default is "test".
A simplest Travis `test` job configures tests in `install` and runs them as `script`, but only on
relevant event conditions.

The `if:` section obviates job creation and resource usage for irrelevant events. Travis does not
support file conditions. A `before_install` step to skip documentation-only commits will likely
complete in less than a minute (10 credit cost).

Here's a partial `.travis.yml` including only the aspects mentioned above.
```yaml
git:
depth: false # TRAVIS_COMMIT_RANGE requires full commit history.
jobs:
include:
- stage: test
if: branch = master AND tag IS blank AND type IN (push, pull_request)
name: Run unit and integration tests
before_install: | # Prevent test build of a documentation-only change.
if [ -n "${TRAVIS_COMMIT_RANGE}" ] && ! git diff --name-only "${TRAVIS_COMMIT_RANGE}" -- | grep -qv '\.md$'; then
echo "Stopping job as changes only affect documentation (ex. README.md)"
travis_terminate 0
fi
install: ./build-bin/configure_test
script: ./build-bin/test
```

When Travis only runs tests (something else does deploy), there's no need to use stages:
```yaml
git:
depth: false # TRAVIS_COMMIT_RANGE requires full commit history.
if: branch = master AND tag IS blank AND type IN (push, pull_request)
before_install: | # Prevent test build of a documentation-only change.
if [ -n "${TRAVIS_COMMIT_RANGE}" ] && ! git diff --name-only "${TRAVIS_COMMIT_RANGE}" -- | grep -qv '\.md$'; then
echo "Stopping job as changes only affect documentation (ex. README.md)"
travis_terminate 0
fi
install: ./build-bin/configure_test
script: ./build-bin/test
```

## Deploy
Deploy builds and pushes artifacts to a remote repository for master and release commits on it. CI
Expand All @@ -138,17 +95,18 @@ master will happen even on README change.

Here's a partial `deploy.yml` including only the aspects mentioned above. Notice env variables are
explicitly defined and `on.tags` is a [glob pattern](https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-syntax-for-github-actions#filter-pattern-cheat-sheet).

```yaml
on:
push:
tags: '[0-9]+.[0-9]+.[0-9]+**' # Ex. 8.272.10 or 15.0.1_p9
tags: '[0-9]+.[0-9]+.[0-9]+**' # e.g. 8.272.10 or 15.0.1_p9
branches: master
jobs:
deploy:
steps:
- name: Checkout Repository
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
fetch-depth: 1 # only needed to get the sha label
- name: Configure Deploy
Expand All @@ -160,51 +118,3 @@ jobs:
# GITHUB_REF will be refs/heads/master or refs/tags/1.2.3
run: build-bin/deploy $(echo ${GITHUB_REF} | cut -d/ -f 3)
```
'[0-9]+.[0-9]+.[0-9]+**'
### Example Travis setup
`.travis.yml` is a monolithic configuration file broken into stages. This means `test` and `deploy`
are in the same file. A simplest Travis `deploy` stage has two jobs: one for master pushes and
another for version tags. These jobs are controlled by event conditions.

The `if:` section obviates job creation and resource usage for irrelevant events. Travis does not
support file conditions. A `before_install` step to skip documentation-only commits will likely
complete in less than a minute (10 credit cost).

As billing is by the minute, it is most cost effective to combine test and deploy on master push.

Here's a partial `.travis.yml` including only the aspects mentioned above. Notice YAML anchors work
in Travis and `tag =~` [condition](https://github.com/travis-ci/travis-conditions) is a regular
expression.
```yaml
git:
depth: false # full git history for license check, and doc-only skipping
_terminate_if_only_docs: &terminate_if_only_docs |
if [ -n "${TRAVIS_COMMIT_RANGE}" ] && ! git diff --name-only "${TRAVIS_COMMIT_RANGE}" -- | grep -qv '\.md$'; then
echo "Stopping job as changes only affect documentation (ex. README.md)"
travis_terminate 0
fi
jobs:
include:
- stage: test
if: branch = master AND tag IS blank AND type IN (push, pull_request)
before_install: *terminate_if_only_docs
install: |
if [ "${TRAVIS_SECURE_ENV_VARS}" = "true" ] && [ "${TRAVIS_PULL_REQUEST}" = "false" ]; then
export SHOULD_DEPLOY=true
./build-bin/configure_deploy
else
export SHOULD_DEPLOY=false
./build-bin/configure_test
fi
script:
- ./build-bin/test || travis_terminate 1
- if [ "${SHOULD_DEPLOY}" != "true" ]; then travis_terminate 0; fi
- travis_wait ./build-bin/deploy master
- stage: deploy
# Ex. 8.272.10 or 15.0.1_p9
if: tag =~ /^[0-9]+\.[0-9]+\.[0-9]+/ AND type = push AND env(GH_TOKEN) IS present
install: ./build-bin/configure_deploy
script: ./build-bin/deploy ${TRAVIS_TAG}
```
7 changes: 1 addition & 6 deletions build-bin/docker/configure_docker
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh
#
# Copyright 2019-2020 The OpenZipkin Authors
# Copyright 2019-2023 The OpenZipkin Authors
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
# in compliance with the License. You may obtain a copy of the License at
Expand All @@ -24,13 +24,8 @@ set -ue
# * See https://www.testcontainers.org/supported_docker_environment/image_registry_rate_limiting/
# * checks.disable=true - saves time and a docker.io pull of alpine
echo checks.disable=true >> ~/.testcontainers.properties
# * change ryuk to ghcr.io until: https://github.com/testcontainers/moby-ryuk/issues/15 and 16
echo ryuk.container.image=ghcr.io/openzipkin/testcontainers-ryuk:latest >> ~/.testcontainers.properties

# We don't use any docker.io images, but add a Google's mirror in case something implicitly does
# * See https://cloud.google.com/container-registry/docs/pulling-cached-images
echo '{ "registry-mirrors": ["https://mirror.gcr.io"] }' | sudo tee /etc/docker/daemon.json
sudo service docker restart

# * Ensure buildx and related features are disabled
mkdir -p ${HOME}/.docker && echo '{"experimental":"disabled"}' > ${HOME}/.docker/config.json
7 changes: 5 additions & 2 deletions build-bin/docker/configure_docker_push
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh
#
# Copyright 2019-2020 The OpenZipkin Authors
# Copyright 2019-2023 The OpenZipkin Authors
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
# in compliance with the License. You may obtain a copy of the License at
Expand Down Expand Up @@ -50,5 +50,8 @@ fi
# See https://github.com/multiarch/qemu-user-static
#
# Mirrored image use to avoid docker.io pulls:
# docker tag multiarch/qemu-user-static:5.1.0-7 ghcr.io/openzipkin/multiarch-qemu-user-static:latest
# docker tag multiarch/qemu-user-static:7.2.0-1 ghcr.io/openzipkin/multiarch-qemu-user-static:latest
#
# Note: This image only works on x86_64/amd64 architecture.
# See: https://github.com/multiarch/qemu-user-static#supported-host-architectures
docker run --rm --privileged ghcr.io/openzipkin/multiarch-qemu-user-static --reset -p yes
10 changes: 9 additions & 1 deletion build-bin/docker/docker_arch
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh
#
# Copyright 2019-2020 The OpenZipkin Authors
# Copyright 2019-2023 The OpenZipkin Authors
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
# in compliance with the License. You may obtain a copy of the License at
Expand All @@ -21,6 +21,8 @@
set -ue

# Normalize docker_arch to what's available
#
# Note: s390x and ppc64le were added for Knative
docker_arch=${DOCKER_ARCH:-$(uname -m)}
case ${docker_arch} in
amd64* )
Expand All @@ -35,6 +37,12 @@ case ${docker_arch} in
aarch64* )
docker_arch=arm64
;;
s390x* )
docker_arch=s390x
;;
ppc64le* )
docker_arch=ppc64le
;;
* )
>&2 echo "Unsupported DOCKER_ARCH: ${docker_arch}"
exit 1;
Expand Down
16 changes: 8 additions & 8 deletions build-bin/docker/docker_args
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh
#
# Copyright 2019-2020 The OpenZipkin Authors
# Copyright 2019-2023 The OpenZipkin Authors
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
# in compliance with the License. You may obtain a copy of the License at
Expand All @@ -25,7 +25,7 @@ if ! test -f ${docker_file}; then
fi

# Add default labels for the day and the SHA we're building from
docker_args="-f ${docker_file} \
docker_args="${DOCKER_ARGS:-} -f ${docker_file} \
--label org.opencontainers.image.created=$(date +%Y-%m-%d) \
--label org.opencontainers.image.revision=$(git rev-parse --short HEAD)"

Expand All @@ -46,21 +46,21 @@ if [ -n "${DOCKER_TARGET}" ]; then
fi

# When non-empty, becomes the base layer including tag appropriate for the image being built.
# Ex. ghcr.io/openzipkin/java:15.0.1_p9-jre
# e.g. ghcr.io/openzipkin/java:21.0.1_p12-jre
#
# This is not required to be a base (FROM scratch) image like ghcr.io/openzipkin/alpine:3.12.1
# This is not required to be a base (FROM scratch) image like ghcr.io/openzipkin/alpine:3.12.3
# See https://docs.docker.com/glossary/#parent-image
if [ -n "${DOCKER_PARENT_IMAGE}" ]; then
docker_args="${docker_args} --build-arg docker_parent_image=${DOCKER_PARENT_IMAGE}"
fi

# When non-empty, becomes the build-arg alpine_version. Ex. "3.12.1"
# When non-empty, becomes the build-arg alpine_version. e.g. "3.12.3"
# Used to align base layers from https://github.com/orgs/openzipkin/packages/container/package/alpine
if [ -n "${ALPINE_VERSION}" ]; then
docker_args="${docker_args} --build-arg alpine_version=${ALPINE_VERSION}"
fi

# When non-empty, becomes the build-arg java_version. Ex. "15.0.1_p9"
# When non-empty, becomes the build-arg java_version. e.g. "21.0.1_p12"
# Used to align base layers from https://github.com/orgs/openzipkin/packages/container/package/java
if [ -n "${JAVA_VERSION}" ]; then
docker_args="${docker_args} --build-arg java_version=${JAVA_VERSION}"
Expand All @@ -69,13 +69,13 @@ if [ -n "${JAVA_VERSION}" ]; then
java_major_version=$(echo ${JAVA_VERSION}| cut -f1 -d .)
case ${java_major_version} in
8) java_home=/usr/lib/jvm/java-1.8-openjdk;;
1?) java_home=/usr/lib/jvm/java-${java_major_version}-openjdk;;
1?|2?|3?) java_home=/usr/lib/jvm/java-${java_major_version}-openjdk;;
esac

if [ -n "${java_home}" ]; then docker_args="${docker_args} --build-arg java_home=${java_home}"; fi
fi

# When non-empty, becomes the build-arg maven_classifier. Ex. "module" or "exec"
# When non-empty, becomes the build-arg maven_classifier. e.g. "module" or "exec"
# Used as the classifier arg to ./build-bin/maven/maven_unjar. Allows building two images with the
# same Dockerfile, varying on classifier, like openzipkin/zipkin vs openzipkin/zipkin-slim
if [ -n "${MAVEN_CLASSIFIER}" ]; then
Expand Down
Loading

0 comments on commit c565a98

Please sign in to comment.