Updated to release via tags #54
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Agent Docker Image - Build and Release | |
on: | |
push: | |
tags: | |
- "v*" | |
env: | |
# Any version upgrade for the OSQuery or Kubectl should be done here | |
OSQUERY_VERSION: 5.12.1 | |
KUBECTL_VERSION: 1.30.0 | |
jobs: | |
build_and_release: | |
name: Build and Release | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
packages: write | |
steps: | |
- name: Extract tagged Agent Docker Image version | |
id: image-version | |
run: echo "version=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT | |
- name: Debug - tag extraction | |
run: echo "Using transformed tag ${{ steps.image-version.outputs.version }}" | |
- name: Query the latest Agent version | |
id: agent-version | |
uses: actions/github-script@v6 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
const query = ` | |
query { | |
repository(owner: "${{ secrets.SOURCE_REPO_OWNER }}", name: "${{ secrets.SOURCE_REPO }}") { | |
releases(first: 1, orderBy: {field: CREATED_AT, direction: DESC}) { | |
nodes { | |
tagName | |
} | |
} | |
} | |
}`; | |
// Extract the latest version from the tag | |
const result = await github.graphql(query); | |
let tagName = result.repository.releases.nodes[0].tagName; | |
if (tagName.startsWith('v')) { | |
tagName = tagName.substring(1); | |
} | |
core.setOutput("version", tagName); | |
- name: Debug - query result | |
run: echo "Using transformed tag ${{ steps.agent-version.outputs.version }}" | |
- name: Versions used for the build | |
run: | | |
echo "DOCKER_VERSION=${{ steps.image-version.outputs.version }}" | |
echo "AGENT_VERSION=${{ steps.agent-version.outputs.version }}" | |
echo "OSQUERY_VERSION=${{ env.OSQUERY_VERSION }}" | |
echo "KUBECTL_VERSION=${{ env.KUBECTL_VERSION }}" | |
- name: Checkout Pipes repository | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Check tag exists | |
run: | | |
TAG="v${{ steps.image-version.outputs.version }}" | |
if [ $(git tag -l "${TAG}") ]; then | |
echo "Tag ${TAG} exists" | |
exit 1 | |
else | |
echo "Tag ${TAG} does not exist - proceeding with build" | |
fi | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Build and push GitHub Container Registry | |
id: docker_build | |
uses: docker/build-push-action@v5 | |
with: | |
context: ./kubernetes/docker | |
push: true | |
platforms: linux/arm64,linux/amd64 | |
tags: | | |
ghcr.io/turbot/guardrails-agent-kubernetes:${{ steps.image-version.outputs.version }} | |
ghcr.io/turbot/guardrails-agent-kubernetes:latest | |
build-args: | | |
OSQUERY_VERSION=${{ env.OSQUERY_VERSION }} | |
KUBECTL_VERSION=${{ env.KUBECTL_VERSION }} | |
AGENT_VERSION=${{ steps.agent-version.outputs.version }} | |
- name: Create Tag | |
run: | | |
git config --global user.name "Turbot Helm Builder" | |
git config --global user.email "[email protected]" | |
git tag v${{ steps.image-version.outputs.version }} | |
git push origin v${{ steps.image-version.outputs.version }} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |