diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 3e25145a0e..c2c2a64b31 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -127,6 +127,7 @@ jobs: runs-on: ubuntu-latest needs: - await-maven-central-artifact + - create-github-release env: SONATYPE_FALLBACK: 1 steps: @@ -143,11 +144,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" diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 480fb99a67..2a5689fa04 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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 release version. 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 release version. An image will be pushed. diff --git a/scripts/docker-release/build_docker.sh b/scripts/docker-release/build_docker.sh index ebcc63c543..26268f279d 100755 --- a/scripts/docker-release/build_docker.sh +++ b/scripts/docker-release/build_docker.sh @@ -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 RELEASE_VERSION=${1} readonly SCRIPT_PATH="$( cd "$(dirname "$0")" ; pwd -P )" readonly PROJECT_ROOT=$SCRIPT_PATH/../../ @@ -36,21 +25,21 @@ then find -E ${PROJECT_ROOT}elastic-apm-agent/target -regex '.*/elastic-apm-agent-[0-9]+.[0-9]+.[0-9]+(-SNAPSHOT)?.jar' -exec cp {} ${PROJECT_ROOT}apm-agent-java.jar \; || echo "INFO: No locally built image found" elif [ ! -z ${SONATYPE_FALLBACK+x} ] then - echo "INFO: No local build artifact and SONATYPE_FALLBACK. Falling back to downloading artifact from Sonatype Nexus repository for version $GIT_TAG" + echo "INFO: No local build artifact and SONATYPE_FALLBACK. Falling back to downloading artifact from Sonatype Nexus repository for version $RELEASE_VERSION" if ! command -v curl then echo "ERROR: Pulling images from Sonatype Nexus repo requires cURL to be installed" && exit 1 fi curl -L -s -o apm-agent-java.jar \ - "https://oss.sonatype.org/service/local/artifact/maven/redirect?r=releases&g=co.elastic.apm&a=elastic-apm-agent&v=$GIT_TAG" + "https://oss.sonatype.org/service/local/artifact/maven/redirect?r=releases&g=co.elastic.apm&a=elastic-apm-agent&v=$RELEASE_VERSION" else echo "ERROR: No suitable build artifact was found. Re-running this script with the SONATYPE_FALLBACK variable set to true will try to use the Sonatype artifact for the latest tag" exit 1 fi -echo "INFO: Starting Docker build for version $GIT_TAG" +echo "INFO: Starting Docker build for version $RELEASE_VERSION" -docker build -t docker.elastic.co/$NAMESPACE/apm-agent-java:$GIT_TAG \ +docker build -t docker.elastic.co/$NAMESPACE/apm-agent-java:$RELEASE_VERSION \ --build-arg JAR_FILE=apm-agent-java.jar \ --build-arg HANDLER_FILE=apm-agent-lambda-layer/src/main/assembly/elastic-apm-handler . diff --git a/scripts/docker-release/push_docker.sh b/scripts/docker-release/push_docker.sh index 2953639ce9..b30fd7e5ad 100755 --- a/scripts/docker-release/push_docker.sh +++ b/scripts/docker-release/push_docker.sh @@ -20,48 +20,24 @@ 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 RELEASE_VERSION=${1} 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" +readonly DOCKER_PUSH_IMAGE="$DOCKER_REGISTRY_URL/$DOCKER_IMAGE_NAME:$RELEASE_VERSION" readonly DOCKER_PUSH_IMAGE_LATEST="$DOCKER_REGISTRY_URL/$DOCKER_IMAGE_NAME:latest" # 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) -if [ "$CUR_TAG" = "$LATEST_TAG" ] +if [ "$RELEASE_VERSION" = "$LATEST_TAG" ] then - echo "INFO: Current version ($CUR_TAG) is the latest version. Tagging and pushing $DOCKER_PUSH_IMAGE_LATEST ..." + echo "INFO: Current version ($RELEASE_VERSION) 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