Skip to content

docker-simtools

docker-simtools #950

# https://docs.github.com/en/actions/publishing-packages/publishing-docker-images
name: docker-simtools
on:
workflow_dispatch:
push:
branches:
- main
tags:
- 'v*'
pull_request:
branches: ["main"]
types: [review_requested, ready_for_review]
release:
types: [published]
schedule:
- cron: '0 0 * * 0' # Every Sunday at 00:00 UTC
env:
SIMTOOLS_DB_SERVER: ${{ secrets.DB_SERVER }}
SIMTOOLS_DB_API_USER: ${{ secrets.DB_READ_USER }}
SIMTOOLS_DB_API_PW: ${{ secrets.DB_READ_PW }}
SIMTOOLS_DB_API_PORT: ${{ secrets.DB_API_PORT }}
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
TEST_TAG: user/app:test
jobs:
build-simtools-container:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
strategy:
matrix:
type: ['dev', 'prod']
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set build arguments (correct branch)
run: |
if [[ "${{ github.event_name }}" == 'pull_request' ]]; then
echo "BUILD_BRANCH=${GITHUB_HEAD_REF}" >> "$GITHUB_ENV"
else
echo "BUILD_BRANCH=${GITHUB_REF#refs/heads/}" >> "$GITHUB_ENV"
fi
echo "BUILD BRANCH ${{ env.BUILD_BRANCH }}"
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
tags: |
type=ref,event=pr
type=semver,pattern={{major}}.{{minor}}.{{patch}}
type=schedule,pattern={{date 'YYYYMMDD'}}
type=raw,value={{date 'YYYYMMDD-HHmmss'}}
images: ${{ env.REGISTRY }}/gammasim/simtools-${{ matrix.type }}
flavor: latest=true
- name: Build Docker image
uses: docker/build-push-action@v6
if: matrix.type == 'prod'
with:
context: .
build-args: BUILD_BRANCH=${{ env.BUILD_BRANCH }}
load: true
file: ./docker/Dockerfile-${{ matrix.type }}
tags: ${{ env.TEST_TAG }}
# test the prod image with one application using the database
# and the sim_telarray installation
- name: Test Docker image
if: matrix.type == 'prod'
run: >
# Clone simulation model repo for faster file access
git clone https://gitlab.cta-observatory.org/cta-science/simulations/simulation-model/model_parameters.git
# run docker
docker run --rm
-e "SIMTOOLS_SIMTEL_PATH='/workdir/sim_telarray'"
-e "SIMTOOLS_DB_API_PORT=${{ env.SIMTOOLS_DB_API_PORT }}"
-e "SIMTOOLS_DB_API_USER=${{ env.SIMTOOLS_DB_API_USER }}"
-e "SIMTOOLS_DB_API_PW=${{ env.SIMTOOLS_DB_API_PW }}"
-e "SIMTOOLS_DB_SERVER=${{ env.SIMTOOLS_DB_SERVER }}"
-e "SIMTOOLS_DB_SIMULATION_MODEL_URL='./model_parameters'"
-v "$(pwd):/workdir/external" ${{ env.TEST_TAG }}
bash -c "cd /workdir/external && simtools-simulate-prod --config /workdir/external/tests/integration_tests/config/simulate_prod_gamma_20_deg_pack_for_grid.yml"
shell: /usr/bin/bash -e {0}
- name: Push Docker image
uses: docker/build-push-action@v6
with:
context: .
build-args: BUILD_BRANCH=${{ env.BUILD_BRANCH }}
platforms: linux/amd64,linux/arm64/v8
push:
${{ github.event_name == 'release' || github.ref == 'refs/heads/main' || github.event_name == 'workflow_dispatch' }}
file: ./docker/Dockerfile-${{ matrix.type }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}-${{ matrix.type }}