Skip to content

fix: repair workflows integrationtests docker #484

fix: repair workflows integrationtests docker

fix: repair workflows integrationtests docker #484

# This workflow will build a Java project with Maven
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
name: Integration test suite
on:
push:
branches: [ "main", "feat/**" ]
pull_request:
branches: [ "main", "feat/**" ]
jobs:
ors-test-scenarios:
name: Build with Maven and Docker caches
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup crabz compression
run: |
echo "Setting up crabz"
curl -sS https://webi.sh/crabz | sh
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '17'
cache: 'maven'
cache-dependency-path: ./pom.xml
- name: Restore cached resources
id: restore-cached-image
continue-on-error: true
uses: actions/cache/restore@v4
with:
path: |
ors-test-scenarios-builder.tar.gz
ors-test-scenarios-war-bare.tar.gz
ors-test-scenarios-jar-bare.tar.gz
ors-test-scenarios-maven-bare.tar.gz
ors-test-scenarios-graphs-integrationtests.tar.gz
key: ${{ runner.os }}-ors-test-scenarios-builder
- name: Load the docker image
id: load-docker-image
run: |
echo "Loading the docker images"
if [ -f ors-test-scenarios-builder.tar.gz ]; then
# Extract the docker image
crabz -d ors-test-scenarios-builder.tar.gz -o ors-test-scenarios-builder.tar
rm -f ors-test-scenarios-builder.tar.gz
docker load -i ors-test-scenarios-builder.tar
docker inspect --format {{.Id}} ors-test-scenarios-builder:latest | awk -F: '{print $2}' > last_image_build_id.log || touch last_image_build_id.log
# I get the docker last image id from a file
last_docker_id=$(cat last_image_build_id.log)
# Add last_docker_id to output
echo "last_docker_id=$last_docker_id" >> "$GITHUB_ENV"
fi
echo "Loading remaining docker images"
if [ -f ors-test-scenarios-war-bare.tar.gz ]; then
crabz -d ors-test-scenarios-war-bare.tar.gz -o ors-test-scenarios-war-bare.tar
rm -f ors-test-scenarios-war-bare.tar.gz
docker load -i ors-test-scenarios-war-bare.tar
fi
if [ -f ors-test-scenarios-jar-bare.tar.gz ]; then
crabz -d ors-test-scenarios-jar-bare.tar.gz -o ors-test-scenarios-jar-bare.tar
rm -f ors-test-scenarios-jar-bare.tar.gz
docker load -i ors-test-scenarios-jar-bare.tar
fi
if [ -f ors-test-scenarios-maven-bare.tar.gz ]; then
crabz -d ors-test-scenarios-maven-bare.tar.gz -o ors-test-scenarios-maven-bare.tar
rm -f ors-test-scenarios-maven-bare.tar.gz
docker load -i ors-test-scenarios-maven-bare.tar
fi
echo "List all docker images"
docker image ls -a
- name: Cache Maven dependencies for the ors maven project
run: |
echo "Caching the maven dependencies"
mvn -pl ors-test-scenarios package -Dmaven.test.skip=true -B dependency:go-offline -q
- name: Test if the graphs need to be rebuilt
id: build-one-shot-image
run: |
echo "Building the docker image with the one shot builder"
mvn -pl ors-test-scenarios -Dtest=utils.OneShotImageBuilderTest#oneShotImageBuilder test
docker inspect --format {{.Id}} ors-test-scenarios-builder:latest | awk -F: '{print $2}' > docker_id_after_build.log || touch docker_id_after_build.log
docker_id_after_build=$(cat docker_id_after_build.log)
# if one is empty or both are different, then rebuild the graphs
if [ -z "${{ env.last_docker_id }}" ] || [ "$docker_id_after_build" != "${{ env.last_docker_id }}" ]; then
echo "Rebuilding the graphs"
rm -rf ors-test-scenarios-graphs-integrationtests.tar.gz
rm -rf ors-test-scenarios/graphs-integrationtests
elif [ -f ors-test-scenarios-graphs-integrationtests.tar.gz ]; then
echo "Docker id after build is the same as the last one, no need to rebuild the graphs"
tar -xvzf ors-test-scenarios-graphs-integrationtests.tar.gz
rm -f ors-test-scenarios-graphs-integrationtests.tar.gz
ls -sahlS ors-test-scenarios/graphs-integrationtests
fi
# Save the last docker id to output
echo "docker_id_after_build=$docker_id_after_build" >> "$GITHUB_ENV"
echo "List all docker images"
docker image ls -a
env:
ONE_SHOT_IMAGE_BUILDER: true
- name: Rebuild shared graphs
run: |
echo "Rebuilding the shared graphs, if needed"
mvn -pl ors-test-scenarios -Dtest=utils.OneShotImageBuilderTest#oneShotGraphBuilder test
env:
ONE_SHOT_IMAGE_BUILDER: true
- name: Run integration tests
run: |
echo "Running integration tests"
mvn -pl ors-test-scenarios test -Dtest=ConfigEnvironmentTest
- name: Export the docker image to be cached
run: |
echo "Exporting the complete builder image"
docker save -o ors-test-scenarios-builder.tar ors-test-scenarios-builder:latest || echo "Could not save ors-test-scenarios-builder"
crabz -l 9 -p $(nproc --all) ors-test-scenarios-builder.tar -o ors-test-scenarios-builder.tar.gz || echo "Could not compress ors-test-scenarios-builder"
rm -f ors-test-scenarios-builder.tar
docker save -o ors-test-scenarios-war-bare.tar ors-test-scenarios-war-bare:latest || echo "Could not save ors-test-scenarios-war-bare"
crabz -l 9 -p $(nproc --all) ors-test-scenarios-war-bare.tar -o ors-test-scenarios-war-bare.tar.gz || echo "Could not save ors-test-scenarios-war-bare"
rm -f ors-test-scenarios-war-bare.tar
docker save -o ors-test-scenarios-jar-bare.tar ors-test-scenarios-jar-bare:latest || echo "Could not save ors-test-scenarios-jar-bare"
crabz -l 9 -p $(nproc --all) ors-test-scenarios-jar-bare.tar -o ors-test-scenarios-jar-bare.tar.gz || echo "Could not save ors-test-scenarios-jar-bare"
rm -f ors-test-scenarios-jar-bare.tar
docker save -o ors-test-scenarios-maven-bare.tar ors-test-scenarios-maven-bare:latest || echo "Could not save ors-test-scenarios-maven-bare"
crabz -l 9 -p $(nproc --all) ors-test-scenarios-maven-bare.tar -o ors-test-scenarios-maven-bare.tar.gz || echo "Could not save ors-test-scenarios-maven-bare"
rm -f ors-test-scenarios-maven-bare.tar
# Tar gz the graphs as well
tar -cv ors-test-scenarios/graphs-integrationtests | crabz -o ors-test-scenarios-graphs-integrationtests.tar.gz
rm -rf ors-test-scenarios/graphs-integrationtests
rm -f ors-test-scenarios-graphs-integrationtests.tar
- name: Delete previously cached resources
continue-on-error: true
run: |
gh extension install actions/gh-actions-cache
gh actions-cache delete "${{ runner.os }}-ors-test-scenarios-builder" --confirm
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Save the resources to cache
uses: actions/cache/save@v4
continue-on-error: true
with:
path: |
ors-test-scenarios-builder.tar.gz
ors-test-scenarios-war-bare.tar.gz
ors-test-scenarios-jar-bare.tar.gz
ors-test-scenarios-maven-bare.tar.gz
ors-test-scenarios-graphs-integrationtests.tar.gz
key: ${{ runner.os }}-ors-test-scenarios-builder