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

Nr 341876 make docker images pre release uniform #103

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
227 changes: 227 additions & 0 deletions .github/workflows/reusable_image_release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,227 @@
name: Reusable Pre Release and Release Pipeline for docker images

on:
workflow_call:
inputs:
original_repo_name:
type: string
required: true
docker_platforms:
type: string
default: 'linux/amd64,linux/arm64,linux/arm'
required: false
docker_image_name:
type: string
required: true
integration_name:
type: string
required: false
default: ''

bucket_url:
type: string
required: false
default: 's3://nr-downloads-main/infrastructure_agent'
go_version_file:
type: string
required: false
default: 'go.mod'
release_command_sh:
type: string
required: true

run_integration_tests:
type: boolean
required: false
default: false
run_nix_unit_tests:
type: boolean
required: false
default: false
run_windows_unit_tests:
type: boolean
required: false
default: false
setup_aws_creds:
type: boolean
required: false
default: false
generate_packages:
type: boolean
required: false
default: false

secrets:
docker_username:
description: 'DockerHub username'
required: true
docker_password:
description: 'DockerHub password'
required: true
bot_token:
description: 'Github Token'
required: true
aws_access_key_id:
description: 'AWS key ID'
required: false
aws_access_key_secret:
description: 'AWS key secret'
required: false

env:
GITHUB_TOKEN: ${{ secrets.bot_token }}
DOCKER_PLATFORMS: ${{ inputs.docker_platforms }}
DOCKER_IMAGE_NAME: ${{ inputs.docker_image_name }}
TAG: ${{ github.event.release.tag_name }}
ORIGINAL_REPO_NAME: ${{ inputs.original_repo_name }}
REPO_FULL_NAME: ${{ github.event.repository.full_name }}
INTEGRATION: ${{ inputs.integration_name }}
S3_PATH: ${{ inputs.bucket_url }}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

S3_PATH and other variables needed only by prometheus can be setup in the build command.

S3_BASE_FOLDER: ${{ inputs.bucket_url }}
PRERELEASE: ${{ github.event.release.prerelease }}
GENERATE_PACKAGES: ${{ inputs.generate_packages }}

jobs:
test-nix:
if: ${{ inputs.run_nix_unit_tests }}
uses: newrelic/coreint-automation/.github/workflows/_test_nix.yaml@v3

test-windows:
if: ${{ inputs.run_windows_unit_tests }}
runs-on: windows-latest
env:
GOPATH: ${{ github.workspace }}
defaults:
run:
working-directory: src/github.com/${{env.ORIGINAL_REPO_NAME}}
steps:
- name: Checkout
uses: actions/checkout@v3
with:
path: src/github.com/${{env.ORIGINAL_REPO_NAME}}
- name: Install Go
uses: actions/setup-go@v5
with:
go-version-file: "src/github.com/${{ env.ORIGINAL_REPO_NAME }}/go.mod"
- name: Running unit tests
shell: pwsh
run: |
.\build\windows\unit_tests.ps1

integration-tests:
name: 🚧 Integration Tests
if: ${{ inputs.run_integration_tests }}
runs-on: ubuntu-latest
strategy:
matrix:
arch: [arm64, amd64]
steps:
- uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.docker_username }}
password: ${{ secrets.docker_password }}
- name: Running integration tests
run: |
make integration-tests-${{ matrix.arch }}

release-integration:
name: Publish container images to registry
needs: [test-nix, test-windows, integration-tests]
if: |
always() &&
(needs.integration-tests.result == 'success' || needs.integration-tests.result == 'skipped') &&
(needs.test-nix.result == 'success' || needs.test-nix.result == 'skipped') &&
(needs.test-windows.result == 'success' || needs.test-windows.result == 'skipped')
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: setup Go
uses: actions/setup-go@v5
with:
go-version-file: ${{ inputs.go_version_file }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.docker_username }}
password: ${{ secrets.docker_password }}

- name: Generate version from tag
run: |
TAG_WITHOUT_V=$(echo "${{ env.TAG }}" | sed 's/^v//')
echo "VERSION=$TAG_WITHOUT_V" >> $GITHUB_ENV
Comment on lines +162 to +165
Copy link
Member

Choose a reason for hiding this comment

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

also this, there if no guarantee the different repos using a custom build command are checking "VERSION"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

All the repos release actions and scripts were modified to use DOCKER_IMAGE_TAG env variable for the tag.
VERSION and TAG_SUFFIX are no longer used.

Copy link
Member

Choose a reason for hiding this comment

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

is it true also for nri-prometheus? I do not see such change in this PR https://github.com/newrelic/nri-prometheus/pull/511/files

echo "DOCKER_IMAGE_TAG=$TAG_WITHOUT_V" >> $GITHUB_ENV

# On pre-releases, the suffix '-pre' is appended to the image tag
# Once all workflows start using the $DOCKER_IMAGE_TAG, $TAG_SUFFIX AND $VERSION can be removed
- name: Add pre-release tag suffix
if: ${{ github.event.release.prerelease }}
run: |
echo "TAG_SUFFIX=-pre" >> $GITHUB_ENV
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since only prometheus needs this. Set this in the prometheus build command.

echo "DOCKER_IMAGE_TAG=${DOCKER_IMAGE_TAG}-pre" >> $GITHUB_ENV

- name: Setup AWS credentials
if: ${{ inputs.setup_aws_creds }}
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.aws_access_key_id }}
aws-secret-access-key: ${{ secrets.aws_access_key_secret }}
aws-region: us-east-1

- name: Run image release commands
run: ${{ inputs.release_command_sh }}
shell: bash
continue-on-error: false

- name: Update title for successful pre-release
if: ${{ github.event.release.prerelease }}
env:
GH_TOKEN: "${{ secrets.bot_token }}"
run: |
gh release edit ${{ github.event.release.tag_name }} --title "${{ github.event.release.tag_name }}"

notify-failure:
if: ${{ always() && failure() }}
needs: [release-integration]
runs-on: ubuntu-latest
steps:
- name: Notify failure via Slack
uses: archive/github-actions-slack@master
with:
slack-bot-user-oauth-access-token: ${{ secrets.COREINT_SLACK_TOKEN }}
slack-channel: ${{ secrets.COREINT_SLACK_CHANNEL }}
slack-text: "❌ `${{ env.ORIGINAL_REPO_NAME }}`: [image release failed](${{ github.server_url }}/${{ env.ORIGINAL_REPO_NAME }}/actions/runs/${{ github.run_id }})."

update-title-on-failure:
if: ${{ always() && failure() }}
needs: [release-integration]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- if: ${{ github.event.release.prerelease }}
name: Reflect failure in pre-release title
env:
GH_TOKEN: "${{ secrets.bot_token }}"
run: |
gh release edit ${{ github.event.release.tag_name }} --title "${{ github.event.release.tag_name }} (pre-release-failure)"

- if: ${{ ! github.event.release.prerelease }}
name: Reflect failure in release title
env:
GH_TOKEN: "${{ secrets.bot_token }}"
run: |
gh release edit ${{ github.event.release.tag_name }} --title "${{ github.event.release.tag_name }} (release-failure)"
Loading