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

ci(quay): set up CI action #6

Merged
merged 29 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
c91ed79
fix hardcoded image tagging
andrewazores Jul 10, 2024
dd98c32
add PUSH_MANIFEST handling
andrewazores Jul 10, 2024
6d8ecf4
add PUSH_MANIFEST handling
andrewazores Jul 10, 2024
a47c838
add PUSH_MANIFEST handling
andrewazores Jul 10, 2024
01b9447
add PUSH_MANIFEST handling when invoking sub-builds
andrewazores Jul 10, 2024
5fd0bdd
set image tags from env var
andrewazores Jul 10, 2024
d917197
add CI workflow
andrewazores Jul 10, 2024
2e1110f
correct agent version retrieval
andrewazores Jul 10, 2024
b170759
install qemu
andrewazores Jul 10, 2024
ab81630
install agent to local m2 before building images
andrewazores Jul 10, 2024
50a6a27
correct manifest push args
andrewazores Jul 10, 2024
a94774d
remove mvn gh pkgs repo
andrewazores Jul 10, 2024
c45bd1f
push all tags
andrewazores Jul 10, 2024
f062899
don't add duplicate 'latest' tag to list
andrewazores Jul 10, 2024
dc13323
don't run maven offline
andrewazores Jul 10, 2024
2a9f3ce
gradle plugin init
andrewazores Jul 10, 2024
f03f1fa
use Agent pom.xml for cache
andrewazores Jul 10, 2024
e01697e
checkout agent as sibling of test-applications, not child
andrewazores Jul 10, 2024
ea26fc7
check out agent within workspace
andrewazores Jul 10, 2024
afd9825
skip building subdirs without build.bash files (ex. cloned -agent dirs)
andrewazores Jul 10, 2024
519f0f5
check out -agent and test-applications to separate subdirs
andrewazores Jul 10, 2024
6dedbaa
agent outside test-applications
andrewazores Jul 10, 2024
fb9a8a4
fixup! agent outside test-applications
andrewazores Jul 10, 2024
5c8110d
fixup! agent outside test-applications
andrewazores Jul 10, 2024
523bf26
share hash key via step output
andrewazores Jul 10, 2024
bfedc5f
avoid recursive build.bash call
andrewazores Jul 10, 2024
0173b7a
use agent JAR from ~/.m2 for gameserver build
andrewazores Jul 10, 2024
1e63061
checkout ref
andrewazores Jul 10, 2024
c17f771
fixup! checkout ref
andrewazores Jul 11, 2024
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
93 changes: 93 additions & 0 deletions .github/workflows/container-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
name: Build Container Image

concurrency:
group: ci-${{ github.run_id }}
cancel-in-progress: true

on:
workflow_dispatch:
schedule:
- cron: '0 0 * * 1' # every Monday at midnight
push:
branches:
- main
- v[0-9]+
- v[0-9]+.[0-9]+
- cryostat-v[0-9]+.[0-9]+

env:
OPENSUSE_UNOFFICIAL_LIBCONTAINERS_KEY_URL: "https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/unstable/xUbuntu_22.04/Release.key"
OPENSUSE_UNOFFICIAL_LIBCONTAINERS_SOURCE_URL: "https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/unstable/xUbuntu_22.04"
CI_USER: redhat-java-monitoring+github_ci
CI_REGISTRY: quay.io
CI_NAMESPACE: redhat-java-monitoring

jobs:
get-agent-version:
runs-on: ubuntu-latest
if: ${{ github.repository_owner == 'cryostatio' }}
outputs:
image-version: ${{ steps.get-agent-version.outputs.agent-version }}
hash-key: ${{ steps.get-hash-key.outputs.hash-key }}
steps:
- uses: actions/checkout@v4
with:
repository: ${{ github.repository_owner }}/cryostat-agent
ref: ${{ github.ref }}
submodules: true
fetch-depth: 0
- id: get-agent-version
run: |
echo "agent-version=$(mvn -q -DforceStdout help:evaluate -Dexpression=project.version)" >> $GITHUB_OUTPUT
- id: get-hash-key
run: |
echo "hash-key=${{ runner.os }}-build-${{ hashFiles('**/pom.xml') }}" >> $GITHUB_OUTPUT
- run: mvn -B -U clean install
- uses: actions/cache@v4
with:
path: ~/.m2
key: ${{ steps.get-hash-key.outputs.hash-key }}

build-and-push:
needs: [get-agent-version]
runs-on: ubuntu-latest
strategy:
matrix:
java: ['17']
env:
agent-version: ${{ needs.get-agent-version.outputs.image-version }}
name: Build Java ${{ matrix.java }}
steps:
- uses: actions/checkout@v4
with:
submodules: true
fetch-depth: 0
- name: Restore Maven Cache
uses: actions/cache@v4
with:
path: ~/.m2
key: ${{ needs.get-agent-version.outputs.hash-key }}
restore-keys: |
${{ runner.os }}-build-
${{ runner.os }}-
- name: Install qemu
run: |
sudo apt-get update
sudo apt-get install -y qemu-user-static
- uses: actions/setup-java@v4
with:
java-version: ${{ matrix.java }}
distribution: 'temurin'
- name: Get date tag
run: echo "DATE_TAG=$(date -uI)" >> "$GITHUB_ENV"
- name: Registry login
run: podman login quay.io --username=${{ env.CI_USER }} --password=${{ secrets.REPOSITORY_TOKEN }}
- name: Build application
run: ./build.bash
env:
TAGS: ${{ env.agent-version }} ${{env.DATE_TAG}} latest
PUSH_MANIFEST: true
APP_REGISTRY: ${{ env.CI_REGISTRY }}
APP_NAMESPACE: ${{ env.CI_NAMESPACE }}
BUILD_TAG: ${{ env.agent-version }}
CRYOSTAT_AGENT_VERSION: ${{ env.agent-version }}
2 changes: 1 addition & 1 deletion build.bash
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ for p in */; do
echo "No build.bash in ${p} !"
exit 1
fi
bash "${p}/build.bash"
PUSH_MANIFEST="${PUSH_MANIFEST:-false}" TAGS="${TAGS:-latest}" bash "${p}/build.bash"
done
1 change: 1 addition & 0 deletions gameserver/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cache/*
21 changes: 1 addition & 20 deletions gameserver/Containerfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,2 @@
ARG CRYOSTAT_AGENT_VERSION=0.5.0-SNAPSHOT

FROM registry.access.redhat.com/ubi8/openjdk-11:latest AS agentloader
ARG CRYOSTAT_AGENT_VERSION
USER 0
RUN mkdir -p /opt/cryostat && \
mvn dependency:get -Dartifact="io.cryostat:cryostat-agent:${CRYOSTAT_AGENT_VERSION}:jar:shaded" && \
mvn dependency:copy -Dartifact="io.cryostat:cryostat-agent:${CRYOSTAT_AGENT_VERSION}:jar:shaded" -DoutputDirectory=/opt/cryostat \
|| true
RUN if [ ! -f "/opt/cryostat/cryostat-agent-${CRYOSTAT_AGENT_VERSION}-shaded.jar" ]; then \
microdnf install git; \
git clone https://github.com/cryostatio/cryostat-agent; \
cd cryostat-agent; \
mvn -DskipTests package; \
cp "target/cryostat-agent-${CRYOSTAT_AGENT_VERSION}-shaded.jar" /opt/cryostat/; \
fi

FROM docker.io/itzg/minecraft-server:java21-jdk
ARG CRYOSTAT_AGENT_VERSION
RUN mkdir -p /opt/cryostat
COPY --from=agentloader /opt/cryostat/cryostat-agent-${CRYOSTAT_AGENT_VERSION}-shaded.jar /opt/cryostat/agent.jar
COPY ./cache/cryostat-agent-*-shaded.jar /opt/cryostat/agent.jar
15 changes: 14 additions & 1 deletion gameserver/build.bash
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,32 @@ DIR="$(dirname "$(readlink -f "$0")")"

pushd "${DIR}"
function cleanup() {
rm -rf "${DIR}/cache"
popd
}
trap cleanup EXIT

BUILD_IMG="${APP_REGISTRY:-quay.io}/${APP_NAMESPACE:-redhat-java-monitoring}/${APP_NAME:-gameserver-cryostat-agent}"
BUILD_TAG="${APP_VERSION:-latest}"
CRYOSTAT_AGENT_VERSION="${CRYOSTAT_AGENT_VERSION:-0.5.0-SNAPSHOT}"

podman manifest create "${BUILD_IMG}:${BUILD_TAG}"

mvn dependency:get -Dartifact="io.cryostat:cryostat-agent:${CRYOSTAT_AGENT_VERSION}:jar:shaded"
mvn dependency:copy -Dartifact="io.cryostat:cryostat-agent:${CRYOSTAT_AGENT_VERSION}:jar:shaded" -DoutputDirectory="${DIR}/cache"

for arch in amd64 arm64; do
echo "Building for ${arch} ..."
podman build --platform="linux/${arch}" -t "${BUILD_IMG}:linux-${arch}" -f "${DIR}/Containerfile" "${DIR}"
podman manifest add "${BUILD_IMG}:${BUILD_TAG}" containers-storage:"${BUILD_IMG}:linux-${arch}"
done

podman tag "${BUILD_IMG}:${BUILD_TAG}" "${BUILD_IMG}:latest"
for tag in ${TAGS}; do
podman tag "${BUILD_IMG}:${BUILD_TAG}" "${BUILD_IMG}:${tag}"
done

if [ "${PUSH_MANIFEST}" = "true" ]; then
for tag in ${TAGS}; do
podman manifest push "${BUILD_IMG}:${tag}" "docker://${BUILD_IMG}:${tag}"
done
fi
12 changes: 10 additions & 2 deletions quarkus-agent/build.bash
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function cleanup() {
trap cleanup EXIT

BUILD_IMG="${APP_REGISTRY:-quay.io}/${APP_NAMESPACE:-redhat-java-monitoring}/${APP_NAME:-quarkus-cryostat-agent}"
BUILD_TAG="${APP_VERSION:-$(mvn -f "${DIR}/pom.xml" help:evaluate -o -B -q -DforceStdout -Dexpression=project.version)}"
BUILD_TAG="${APP_VERSION:-$(mvn -f "${DIR}/pom.xml" help:evaluate -B -q -DforceStdout -Dexpression=project.version)}"

"${DIR}/mvnw" -DskipTests clean package

Expand All @@ -23,4 +23,12 @@ for arch in amd64 arm64; do
podman manifest add "${BUILD_IMG}:${BUILD_TAG}" containers-storage:"${BUILD_IMG}:linux-${arch}"
done

podman tag "${BUILD_IMG}:${BUILD_TAG}" "${BUILD_IMG}:latest"
for tag in ${TAGS}; do
podman tag "${BUILD_IMG}:${BUILD_TAG}" "${BUILD_IMG}:${tag}"
done

if [ "${PUSH_MANIFEST}" = "true" ]; then
for tag in ${TAGS}; do
podman manifest push "${BUILD_IMG}:${tag}" "docker://${BUILD_IMG}:${tag}"
done
fi
6 changes: 0 additions & 6 deletions quarkus-agent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,6 @@
<groupId>org.acme</groupId>
<artifactId>code-with-quarkus</artifactId>
<version>1.0.0-SNAPSHOT</version>
<repositories>
<repository>
<id>github</id>
<url>https://maven.pkg.github.com/cryostatio/cryostat-agent</url>
</repository>
</repositories>
<properties>
<compiler-plugin.version>3.8.1</compiler-plugin.version>
<maven.compiler.parameters>true</maven.compiler.parameters>
Expand Down
12 changes: 11 additions & 1 deletion vertx-fib/build.bash
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ set -xe

DIR="$(dirname "$(readlink -f "$0")")"

sh "${DIR}/gradlew" -p "${DIR}" compileJava > /dev/null 2>&1 # initialize gradle plugins etc. before trying to parse project version

BUILD_IMG="${APP_REGISTRY:-quay.io}/${APP_NAMESPACE:-redhat-java-monitoring}/${APP_NAME:-vertx-cryostat-agent}"
BUILD_TAG="${APP_VERSION:-$(sh "${DIR}/gradlew" -p "${DIR}" -q printVersion)}"

Expand All @@ -15,4 +17,12 @@ for arch in amd64 arm64; do
podman manifest add "${BUILD_IMG}:${BUILD_TAG}" containers-storage:"${BUILD_IMG}:linux-${arch}"
done

podman tag "${BUILD_IMG}:${BUILD_TAG}" "${BUILD_IMG}:latest"
for tag in ${TAGS}; do
podman tag "${BUILD_IMG}:${BUILD_TAG}" "${BUILD_IMG}:${tag}"
done

if [ "${PUSH_MANIFEST}" = "true" ]; then
for tag in ${TAGS}; do
podman manifest push "${BUILD_IMG}:${tag}" "docker://${BUILD_IMG}:${tag}"
done
fi
6 changes: 5 additions & 1 deletion vertx-fib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ def baseImageTag = 'latest';
def buildArch = System.getenv('JIB_ARCH') ?: 'amd64'
def buildOs = 'linux'

def appRegistry = System.getenv('APP_REGISTRY') ?: 'quay.io'
def appNamespace = System.getenv('APP_NAMESPACE') ?: 'redhat-java-monitoring'
def appName = System.getenv('APP_NAME') ?: 'vertx-cryostat-agent'

jib {
from {
image = baseImage + ':' + baseImageTag
Expand All @@ -40,7 +44,7 @@ jib {
}
}
to {
image = "quay.io/redhat-java-monitoring/vertx-cryostat-agent"
image = appRegistry + '/' + appNamespace + '/' + appName
tags = [buildOs + '-' + buildArch]
}
dockerClient {
Expand Down