Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release: use tag version for docker build/push #3600

Merged
merged 6 commits into from
Apr 29, 2024
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -126,6 +126,7 @@ jobs:
runs-on: ubuntu-latest
needs:
- await-maven-central-artifact
- create-github-release
env:
SONATYPE_FALLBACK: 1
steps:
@@ -142,11 +143,11 @@ jobs:
secretId: ${{ secrets.VAULT_SECRET_ID }}
- name: "Build docker image"
shell: bash
run: ./scripts/docker-release/build_docker.sh
run: ./scripts/docker-release/build_docker.sh "${{ env.RELEASE_VERSION }}"
- name: "Push docker image"
if: ${{ ! inputs.dry_run }}
shell: bash
run: ./scripts/docker-release/push_docker.sh
run: ./scripts/docker-release/push_docker.sh "${{ env.RELEASE_VERSION }}"

publish-aws-lambda:
name: "Publish AWS Lambda"
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -354,7 +354,7 @@ If you wish to use a locally built artifact in the built image, execute [`./mvnw
and ensure that artifacts are present in `elastic-apm-agent/target/*.jar`.

To create a Docker image from artifacts generated by [`./mvnw package`](mvnw),
run [`scripts/docker-release/build_docker.sh`](scripts/docker-release/build_docker.sh).
run [`scripts/docker-release/build_docker.sh`](scripts/docker-release/build_docker.sh) with the tag version.
v1v marked this conversation as resolved.
Show resolved Hide resolved

Alternatively, it is also possible to use the most recent artifact from the [Sonatype
repository](https://oss.sonatype.org/#nexus-search;gav~co.elastic.apm~apm-agent-java~~~).
@@ -383,4 +383,4 @@ Prior to pushing images, you must login to the Elastic Docker repo using the cor
credentials using the [`docker login`](https://docs.docker.com/engine/reference/commandline/login/) command.

To push an image, run the [`scripts/docker-release/push_docker.sh`](scripts/docker-release/push_docker.sh)
script. An image will be pushed.
script with the tag version. An image will be pushed.
v1v marked this conversation as resolved.
Show resolved Hide resolved
13 changes: 1 addition & 12 deletions scripts/docker-release/build_docker.sh
Original file line number Diff line number Diff line change
@@ -12,18 +12,7 @@ elif ! docker version
then
echo "ERROR: Building Docker image requires Docker daemon to be running" && exit 1
fi

echo "INFO: Determining latest tag"
if [ ! -z ${TAG_NAME+x} ]
then
echo "INFO: Detected TAG_NAME variable. Probably a Jenkins instance."
readonly GIT_TAG_DEFAULT=$(echo $TAG_NAME|sed s/^v//)
else
echo "INFO: Did not detect TAG_NAME. Examining git log for latest tag"
readonly GIT_TAG_DEFAULT=$(git describe --abbrev=0|sed s/^v//)
fi

readonly GIT_TAG=${GIT_TAG:-$GIT_TAG_DEFAULT}
readonly GIT_TAG=${1}
v1v marked this conversation as resolved.
Show resolved Hide resolved
v1v marked this conversation as resolved.
Show resolved Hide resolved

readonly SCRIPT_PATH="$( cd "$(dirname "$0")" ; pwd -P )"
readonly PROJECT_ROOT=$SCRIPT_PATH/../../
30 changes: 3 additions & 27 deletions scripts/docker-release/push_docker.sh
Original file line number Diff line number Diff line change
@@ -20,22 +20,9 @@ readonly RETRIES=3
# creating a Docker image to push. If this script does not detect an image
# to be uploaded, it will fail.

# This script is intended to be run from a CI job and will not work if run in
# standalone manner unless certain envrionment variables are set.

# Grab the tag we are working with

echo "INFO: Determining latest tag"
if [ ! -z ${TAG_NAME+x} ]
then
echo "INFO: Detected TAG_NAME variable. Probably a Jenkins instance."
readonly GIT_TAG_DEFAULT=$(echo $TAG_NAME|sed s/^v//)
else
echo "INFO: Did not detect TAG_NAME. Examining git log for latest tag"
readonly GIT_TAG_DEFAULT=$(git describe --abbrev=0|sed s/^v//)
fi

readonly CUR_TAG=${CUR_TAG:-$GIT_TAG_DEFAULT}
readonly CUR_TAG=${1}
v1v marked this conversation as resolved.
Show resolved Hide resolved
readonly DOCKER_REGISTRY_URL="docker.elastic.co"
readonly DOCKER_IMAGE_NAME="observability/apm-agent-java"
readonly DOCKER_PUSH_IMAGE="$DOCKER_REGISTRY_URL/$DOCKER_IMAGE_NAME:$CUR_TAG"
@@ -44,24 +31,13 @@ readonly DOCKER_PUSH_IMAGE_LATEST="$DOCKER_REGISTRY_URL/$DOCKER_IMAGE_NAME:lates
# Proceed with pushing to the registry
echo "INFO: Pushing image $DOCKER_PUSH_IMAGE to $DOCKER_REGISTRY_URL"

if [ ${WORKERS+x} ] # We are on a CI worker
then
retry $RETRIES docker push $DOCKER_PUSH_IMAGE || echo "Push failed after $RETRIES retries"
else # We are in a local (non-CI) environment
docker push $DOCKER_PUSH_IMAGE || { echo "You may need to run 'docker login' first and then re-run this script"; exit 1; }
fi
docker push $DOCKER_PUSH_IMAGE || { echo "You may need to run 'docker login' first and then re-run this script"; exit 1; }

readonly LATEST_TAG=$(git tag --list --sort=version:refname "v*" | grep -v RC | sed s/^v// | tail -n 1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] this one is actually the "latest version", not the "latest tag".

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want me to change it?


if [ "$CUR_TAG" = "$LATEST_TAG" ]
then
echo "INFO: Current version ($CUR_TAG) is the latest version. Tagging and pushing $DOCKER_PUSH_IMAGE_LATEST ..."
docker tag $DOCKER_PUSH_IMAGE $DOCKER_PUSH_IMAGE_LATEST

if [ ${WORKERS+x} ] # We are on a CI worker
then
retry $RETRIES docker push $DOCKER_PUSH_IMAGE_LATEST || echo "Push failed after $RETRIES retries"
else # We are in a local (non-CI) environment
docker push $DOCKER_PUSH_IMAGE_LATEST || { echo "You may need to run 'docker login' first and then re-run this script"; exit 1; }
fi
docker push $DOCKER_PUSH_IMAGE_LATEST || { echo "You may need to run 'docker login' first and then re-run this script"; exit 1; }
fi