Build also arm64 Docker image #108
Workflow file for this run
This file contains hidden or 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: CD | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
jobs: | |
publish_docker_image_to_docker_hub: | |
name: Build & Push docker image to dockerhub | |
runs-on: ubuntu-24.04 | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Get metadata as environment variables | |
uses: HSLdevcom/jore4-tools/github-actions/extract-metadata@extract-metadata-v1 | |
- name: Pull previous images to support caching | |
run: | | |
docker pull $IMAGE_NAME:latest || echo "Previous image not found" | |
docker pull $IMAGE_NAME:empty || echo "Previous image not found" | |
docker pull $IMAGE_NAME:schema-only || echo "Previous image not found" | |
- name: Build docker images | |
run: | | |
# build docker image containing the MSSQL service only, no data | |
docker build \ | |
--cache-from=$IMAGE_NAME:latest \ | |
--cache-from=$IMAGE_NAME:empty \ | |
-t $IMAGE_NAME:empty \ | |
-t $IMAGE_NAME:latest \ | |
-t $IMAGE_NAME:empty-$COMMIT_ID \ | |
--target empty . | |
# build docker image containing the jore3 test schema, no data | |
docker build \ | |
--cache-from=$IMAGE_NAME:latest \ | |
--cache-from=$IMAGE_NAME:schema-only \ | |
-t $IMAGE_NAME:schema-only \ | |
-t $IMAGE_NAME:schema-only-$COMMIT_ID \ | |
--target schema-only . | |
- name: Login to Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.JORE4_DOCKERHUB_USER }} | |
password: ${{ secrets.JORE4_DOCKERHUB_TOKEN }} | |
- name: Push images tagged with git commit details to Docker Hub | |
run: | | |
docker push $IMAGE_NAME:empty-$COMMIT_ID | |
docker push $IMAGE_NAME:schema-only-$COMMIT_ID | |
- name: Push rest of the tags to Docker Hub | |
if: ${{ github.ref == 'refs/heads/main' }} | |
run: | | |
docker push $IMAGE_NAME:empty | |
docker push $IMAGE_NAME:schema-only | |
docker push $IMAGE_NAME:latest | |
publish_docker_image_to_acr: | |
name: Publish Docker image to ACR | |
permissions: | |
id-token: write | |
contents: read | |
uses: HSLdevcom/jore4-tools/.github/workflows/shared-build-and-publish-docker-image.yml@shared-build-and-publish-docker-image-v1 | |
with: | |
docker_image_name: jore4-mssql-testdb | |
build_arm64_image: true | |
secrets: | |
azure_client_id: ${{ secrets.AZURE_CLIENT_ID }} | |
azure_tenant_id: ${{ secrets.AZURE_TENANT_ID }} | |
azure_subscription_id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} | |
test-docker-images: | |
name: verify that the docker images work | |
needs: publish_docker_image_to_acr | |
runs-on: ubuntu-24.04 | |
env: | |
SA_PASSWORD: "P@ssw0rd" | |
strategy: | |
matrix: | |
include: | |
# no test dumps are imported | |
- volumeMapping: "" | |
expectedOutput: | | |
name | |
-------------------------------------------------------------------------------------------------------------------------------- | |
jore3testdb | |
master | |
model | |
msdb | |
tempdb | |
(5 rows affected) | |
# test dumps are imported | |
- volumeMapping: ' -v "$(pwd)/docker-image-test-data:/data:ro"' | |
expectedOutput: | | |
name | |
-------------------------------------------------------------------------------------------------------------------------------- | |
bardb | |
foodb | |
jore3testdb | |
master | |
model | |
msdb | |
tempdb | |
(7 rows affected) | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Get metadata as environment variables | |
uses: HSLdevcom/jore4-tools/github-actions/extract-metadata@extract-metadata-v1 | |
- name: Read Current MS SQL Docker Image | |
id: docker | |
shell: bash | |
run: | | |
echo mssql_docker_image="$(grep FROM Dockerfile | sed -E 's/FROM *([^ ]*)( AS.*)?/\1/g' | head -n 1)" >> "${GITHUB_OUTPUT}" | |
- name: Start up mssql docker container | |
run: | | |
# A custom network is used so that Docker containers can be referred with names instead of IPs | |
docker network rm hsl || true | |
docker network create -d bridge --subnet=10.240.0.0/24 hsl | |
docker network ls | |
docker run \ | |
-d \ | |
--rm \ | |
-p 1433:1433 \ | |
--name mssql \ | |
--hostname mssql \ | |
--network hsl \ | |
-e SA_PASSWORD="$SA_PASSWORD" \ | |
${{ matrix.volumeMapping }} \ | |
"${{ needs.publish_docker_image_to_acr.outputs.docker_image }}" | |
- name: | |
Verify that dockerized MSSQL database is up and can be connected to | |
uses: HSLdevcom/jore4-tools/github-actions/healthcheck@healthcheck-v1 | |
with: | |
command: | |
'docker run | |
--network hsl | |
${{ steps.docker.outputs.mssql_docker_image }} | |
/opt/mssql-tools18/bin/sqlcmd | |
-C | |
-S mssql | |
-U sa | |
-P "$SA_PASSWORD" | |
-d master | |
-Q "SELECT ''OK'';"' | |
- name: | |
Verify that the proper sql dumps got imported (diff expected results) | |
env: | |
# query for listing all available database names | |
DB_QUERY: "SELECT name FROM master.sys.databases ORDER BY name;" | |
# A custom entrypoint needs to be used so that the output does not contain lines printed by | |
# the default entrypoint which would make the diff fail | |
run: | | |
docker run \ | |
--network hsl \ | |
--entrypoint /opt/mssql-tools18/bin/sqlcmd \ | |
${{ steps.docker.outputs.mssql_docker_image }} \ | |
-C \ | |
-S mssql \ | |
-U sa \ | |
-P "$SA_PASSWORD" \ | |
-d master \ | |
-Q "$DB_QUERY" \ | |
> dbresults.txt | |
echo "${{ matrix.expectedOutput }}" > expectedresults.txt | |
diff --ignore-all-space --ignore-blank-lines dbresults.txt expectedresults.txt |