Skip to content

Commit

Permalink
ci(quay): set up CI action (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewazores authored Jul 11, 2024
1 parent 919dc36 commit 261d7c0
Show file tree
Hide file tree
Showing 9 changed files with 136 additions and 32 deletions.
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

0 comments on commit 261d7c0

Please sign in to comment.