Skip to content

ops: update software versions for testing #224

ops: update software versions for testing

ops: update software versions for testing #224

Workflow file for this run

---
name: Build the ambit-docker images
on: # yamllint disable-line rule:truthy
workflow_dispatch:
repository_dispatch:
types:
- ambit-repo-push
push:
branches:
- master
- ci-updates
jobs:
set-test-matrices:
runs-on: ubuntu-latest
outputs:
matrix-db: ${{ steps.db.outputs.matrix }}
war-db: ${{ steps.db.outputs.war-db }}
steps:
- name: Checkout the repository
uses: actions/checkout@v6.0.1
- name: Determining the RDBMS test matrix
id: db
env:
prefix: ci/ambit-db
awk_get_tags_json: >-
BEGIN { printf "[" }
NR > 1 { printf "," }
{
split($1, arr, "-");
printf "\"" arr[1] ":" arr[2] "\"";
}
END { printf "]" }
awk_get_war_from_db: >-
/\<latest\>/ {
split($1, arr, "-");
printf arr[1] ":" arr[2];
}
run: |
matrix_json="$( awk "${awk_get_tags_json}" '${{ env.prefix }}/tags.txt')"
jq . <<<"${matrix_json}" # lint
echo "matrix=${matrix_json}" >> $GITHUB_OUTPUT
war_db="$( awk "${awk_get_war_from_db}" '${{ env.prefix }}/tags.txt')"
echo "war-db=${war_db}" >> $GITHUB_OUTPUT
build-ambit:
needs: [set-test-matrices]
runs-on: ubuntu-latest
strategy:
matrix:
java-distribution: ['temurin', 'corretto']
java-version: [8, 11, 17, 21, 25]
rdbms-version: ${{ fromJson(needs.set-test-matrices.outputs.matrix-db) }}
fail-fast: false
env:
rdbms_ctnr_name: gh-act-rdbms-test
outputs:
job-status: ${{ job.status }}
steps:
- name: Checkout the AMBIT repository
uses: actions/checkout@v6.0.1
with:
repository: ideaconsult/ambit-mirror
ref: ${{ github.event.client_payload.sha }}
token: ${{ secrets.GH_R_PR }}
- name: 'Set up OpenJDK: ${{ matrix.java-distribution }}/${{ matrix.java-version }}'
uses: actions/setup-java@v5.1.0
with:
distribution: ${{ matrix.java-distribution }}
java-version: ${{ matrix.java-version }}
server-id: github # Value of the distributionManagement/repository/id field of the pom.xml
settings-path: ${{ github.workspace }} # location for the settings.xml file
- name: Set up Maven if using act
if: ${{ env.ACT }}
env:
maven_version: 3.6.3
run: >-
wget -P /tmp
"https://mirrors.netix.net/apache/maven/maven-3/${maven_version}/binaries/apache-maven-${maven_version}-bin.tar.gz";
tar xf "/tmp/apache-maven-${maven_version}-bin.tar.gz" -C /opt;
ln -s -t /usr/bin "/opt/apache-maven-${maven_version}/bin/mvn"
- name: Cache the local Maven repository
uses: actions/cache@v4.3.0
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: Set up a RDBMS for unit testing
env:
rdbms_test_db_name: ambit-test
rdbms_test_db_user: guest
rdbms_test_db_pass: guest
rdbms_init_timeout: '30'
run: >-
docker_cmd=(
'docker'
'run'
"--name=${rdbms_ctnr_name}"
'--detach'
"--env=MYSQL_DATABASE=${rdbms_test_db_name}"
"--env=MYSQL_USER=${rdbms_test_db_user}"
"--env=MYSQL_PASSWORD=${rdbms_test_db_pass}"
'--env=MYSQL_RANDOM_ROOT_PASSWORD=1'
'--publish=127.0.0.1:3306:3306'
'${{ matrix.rdbms-version }}'
)
rdbms_xtra_cfg=(
'[client]'
'host = 127.0.0.1'
"user = \"${rdbms_test_db_user}\""
"password = \"${rdbms_test_db_pass}\""
'silent'
)
mysqladmin_cmd=(
'mysqladmin'
'--defaults-extra-file=rdbms-xtra.cfg'
'version'
)
# NOTE: Don't remove the empty line after the following comments. Because of how the YAML
# block scalars are parsed, the command will otherwise become part of the comment line.
# Start the RDBMS container.
"${docker_cmd[@]}"
# Use a config file to avoid the "password on the command line" warning.
OLD_IFS="$IFS";
IFS=$'\n';
printf '%s\n' "${rdbms_xtra_cfg[*]}" >rdbms-xtra.cfg;
IFS="$OLD_IFS"
;cat rdbms-xtra.cfg
# Wait for the RDBMS to become operational.
# Note that the output should contain the version information. If it doesn't,
# but the step still succeeds, there's a problem with the auth credentials.
for (( tmout=${rdbms_init_timeout}; tmout > 0; tmout-- )); do
[[ ${tmout} -lt ${rdbms_init_timeout} ]] && sleep 1;
"${mysqladmin_cmd[@]}" && exit 0;
done; false
- name: Build with Maven (ambit-all)
run: >-
mvn
-B -f ambit2-all/pom.xml
clean install
- name: Build with Maven (ambit-apps)
run: >-
mvn
-B -f ambit2-apps/pom.xml
-DskipTests=true
-P docker_generic
-P http
clean install
- name: Build with Maven (ambit-www)
run: >-
mvn
-B -f ambit2-apps/ambit2-www/pom.xml
-DskipTests=true
-P docker_generic
-P http
clean package
- name: Stop the RDBMS for unit testing
run: docker stop "${rdbms_ctnr_name}"
- name: Save the newly build WAR
# Only the one tested with the RDBMS marked with our "latest" image tag,
# and only for the Java distribution that we build our images with.
if: >
matrix.rdbms-version == needs.set-test-matrices.outputs.war-db &&
matrix.java-distribution == 'temurin'
uses: actions/upload-artifact@v5.0.0
with:
name: ambit-war-java${{ matrix.java-version }}
path: ambit2-apps/ambit2-www/target/ambit2.war
retention-days: 1
set-build-matrices:
runs-on: ubuntu-latest
outputs:
matrix-api: ${{ steps.api.outputs.matrix }}
matrix-db: ${{ steps.db.outputs.matrix }}
job-status: ${{ job.status }}
steps:
- name: Checkout the repository
uses: actions/checkout@v6.0.1
- name: Determining the ambit-api build matrix
id: api
env:
prefix: ci/ambit-api
run: |
export matrix_list="$(awk 'NR > 1 { printf ", " } { printf "\"" $1 "\"" }' '${{ env.prefix }}/tags.txt')"
export matrix_json="{\"ver\":[${matrix_list}]}"
jq . <<<"$matrix_json" # lint
echo "matrix=${matrix_json}" >> $GITHUB_OUTPUT
- name: Determine the build matrix
id: db
env:
prefix: ci/ambit-db
run: |
export matrix_list="$(awk 'NR > 1 { printf ", " } { printf "\"" $1 "\"" }' '${{ env.prefix }}/tags.txt')"
export matrix_json="{\"ver\":[${matrix_list}]}"
jq . <<<"$matrix_json" # lint
echo "matrix=${matrix_json}" >> $GITHUB_OUTPUT
build-images-api:
needs: [build-ambit, set-build-matrices]
runs-on: ubuntu-latest
strategy:
matrix: ${{ fromJson(needs.set-build-matrices.outputs.matrix-api) }}
env:
image: ambit-api
outputs:
job-status: ${{ job.status }}
steps:
- name: Checkout the repository
uses: actions/checkout@v6.0.1
- name: Identify the OpenJDK version
run: |
export java_version="$(echo ${{ matrix.ver }} | sed 's|.*-jdk\([[:digit:]]\+\)-.*|\1|')"
echo "java_version=${java_version}" >>"$GITHUB_ENV"
- name: Load the latest WAR for the required OpenJDK version
uses: actions/download-artifact@v6.0.0
with:
name: ambit-war-java${{ env.java_version }}
path: ./ci/${{ env.image }}/${{ matrix.ver }}
- name: Determine the image tags
run: >-
export tags_list="$(
while read repo; do
for tag in $(grep '${{ matrix.ver }}' './ci/${{ env.image }}/tags.txt'); do
printf ',%s/%s:%s' "$repo" "$image" "$tag";
done;
done <'./ci/${{ env.image }}/repos.txt'
)";
echo "image_tags=${tags_list:1}" >>"$GITHUB_ENV"
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3.11.1
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3.6.0
with:
registry: ghcr.io
username: idea-docker
password: ${{ secrets.GH_CR_FA }}
- name: Log in to Docker Hub
uses: docker/login-action@v3.6.0
with:
username: kerberizer
password: ${{ secrets.DCKR_TOKEN }}
- name: Build the ambit-api image
uses: docker/build-push-action@v6.18.0
with:
context: ./ci/${{ env.image }}/${{ matrix.ver }}
outputs: type=docker,dest=ambit-api.docker.tar
pull: true
push: ${{ github.ref == 'refs/heads/master' }} # push only if we're on the master branch
tags: ${{ env.image_tags }}
- name: Upload the built image as artifact for download
uses: actions/upload-artifact@v5.0.0
with:
name: ambit-api.docker.tar
path: ambit-api.docker.tar
build-images-db:
needs: set-build-matrices
runs-on: ubuntu-latest
strategy:
matrix: ${{ fromJson(needs.set-build-matrices.outputs.matrix-db) }}
env:
image: ambit-db
outputs:
job-status: ${{ job.status }}
steps:
- name: Checkout the repository
uses: actions/checkout@v6.0.1
- name: Determine the image tags
run: >-
export tags_list="$(
while read repo; do
for tag in $(grep '${{ matrix.ver }}' './ci/${{ env.image }}/tags.txt'); do
printf ',%s/%s:%s' "$repo" "$image" "$tag";
done;
done <'./ci/${{ env.image }}/repos.txt'
)";
echo "image_tags=${tags_list:1}" >>"$GITHUB_ENV"
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3.11.1
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3.6.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Log in to Docker Hub
uses: docker/login-action@v3.6.0
with:
username: ${{ secrets.DCKR_USER }}
password: ${{ secrets.DCKR_TOKEN }}
- name: Build the ambit-db image
uses: docker/build-push-action@v6.18.0
with:
context: ./ci/${{ env.image }}/${{ matrix.ver }}
outputs: type=docker,dest=ambit-db.docker.tar
pull: true
push: ${{ github.ref == 'refs/heads/master' }} # push only if we're on the master branch
tags: ${{ env.image_tags }}
- name: Upload the built image as artifact for download
uses: actions/upload-artifact@v5.0.0
with:
name: ambit-db.docker.tar
path: ambit-db.docker.tar
integration-testing:
needs: [build-images-api, build-images-db]
runs-on: ubuntu-latest
steps:
- name: Checkout the repository
uses: actions/checkout@v6.0.1
- name: Spin up a default Docker Compose setup
run: |
docker compose pull
docker compose up --detach
- name: Wait for the API to become operational
run: |
for ((;;)) {
sleep 1
curl -s http://127.0.0.1:{8080,8081}/ambit/algorithm && break
}
- name: Run the API tests
run: ./ci/run_integration_tests.sh
- name: Bring down the Docker Compose setup
run: docker compose down --volumes
# FIXME: Temporarily not sending notifications to Discord until we manage to send the final status.
# send-notifications:
#
# needs: [build-ambit, set-build-matrices, build-images-api, build-images-db]
# if: always()
# runs-on: ubuntu-latest
#
# steps:
#
# - name: Determine the final action status
# env:
# job-statuses: >-
# ${{ needs.build-ambit.outputs.job-status }}
# ${{ needs.set-build-matrices.outputs.job-status }}
# ${{ needs.build-images-api.outputs.job-status }}
# ${{ needs.build-images-db.outputs.job-status }}
# run: |
# for status in ${{ env.job-statuses }}; do
# case "$status" in
# cancelled | failure )
# final_status=$status
# break
# ;;
# success)
# final_status=$status
# continue
# ;;
# *)
# final_status=failure
# break
# ;;
# esac
# done
# echo "final_status=$final_status" >>"$GITHUB_ENV"
#
# - name: Send Discord notification
# uses: kerberizer/actions-status-discord@master
# with:
# webhook: ${{ secrets.DISCORD_WEBHOOK }}
# status: ${{ env.final_status }}