|
| 1 | +name: Build Fenix's Environment Image |
| 2 | + |
| 3 | +on: |
| 4 | + # workflow_call = called by another workflow |
| 5 | + workflow_call: |
| 6 | + inputs: |
| 7 | + ompi_version: |
| 8 | + description: "Open MPI version to build" |
| 9 | + type: string |
| 10 | + required: true |
| 11 | + max_age: |
| 12 | + description: "Maximum image age before rebuild, in days" |
| 13 | + type: number |
| 14 | + required: false |
| 15 | + default: 14 |
| 16 | + # workflow_dispatch = manual trigger |
| 17 | + workflow_dispatch: |
| 18 | + inputs: |
| 19 | + ompi_version: |
| 20 | + description: "Open MPI version to build" |
| 21 | + type: string |
| 22 | + required: true |
| 23 | + max_age: |
| 24 | + description: "Maximum image age before rebuild, in days" |
| 25 | + type: number |
| 26 | + required: false |
| 27 | + default: 0 |
| 28 | + |
| 29 | +env: |
| 30 | + IMAGE_NAME: ghcr.io/sandialabs/fenix/env |
| 31 | + IMAGE_TAG: ${{ github.event.inputs.ompi_version }} |
| 32 | + |
| 33 | +jobs: |
| 34 | + detect_image: |
| 35 | + runs-on: ubuntu-latest |
| 36 | + steps: |
| 37 | + - name: Check for valid image |
| 38 | + run: | |
| 39 | + IMG=${IMAGE_NAME}:${{ inputs.ompi_version }} |
| 40 | + docker image rm -f $IMG; docker pull $IMG || true |
| 41 | + IMG_CREATED=$(docker inspect --type=image --format '{{.Created}}' $IMG 2>/dev/null) |
| 42 | + if [ -z "$IMG_CREATED" ]; then |
| 43 | + echo "found=false" >> $GITHUB_OUTPUT |
| 44 | + exit 0 |
| 45 | + fi |
| 46 | +
|
| 47 | + IMG_AGE=$(( ($(date +%s) - $(date -d "$IMG_CREATED" +%s)) / (60*60*24) )) |
| 48 | + if [ "$IMG_AGE" -lt ${{ github.event.inputs.max_age }} ]; then |
| 49 | + echo "found=true" >> $GITHUB_OUTPUT |
| 50 | + else |
| 51 | + echo "found=false" >> $GITHUB_OUTPUT |
| 52 | + fi |
| 53 | + outputs: |
| 54 | + found: ${{ job.steps.outputs.found }} |
| 55 | + |
| 56 | + build_image: |
| 57 | + runs-on: ubuntu-latest |
| 58 | + needs: detect_image |
| 59 | + if: needs.detect_image.outputs.found == 'false' |
| 60 | + steps: |
| 61 | + - name: Checkout repository |
| 62 | + uses: actions/checkout@v3 |
| 63 | + |
| 64 | + - name: Set up Docker Buildx |
| 65 | + uses: docker/setup-buildx-action@v2 |
| 66 | + |
| 67 | + - name: Log in to GHCR container registry |
| 68 | + uses: docker/login-action@v3 |
| 69 | + with: |
| 70 | + registry: ghcr.io |
| 71 | + username: ${{ github.actor }} |
| 72 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 73 | + |
| 74 | + - name: Bake the bootstrap docker image |
| 75 | + uses: docker/bake-action@v5 |
| 76 | + with: |
| 77 | + files: .github/docker-compose.yml |
| 78 | + targets: bootstrap |
| 79 | + workdir: . |
| 80 | + set: | |
| 81 | + *.output=type=docker,name=bootstrap |
| 82 | + *.cache-from=type=gha,scope=bootstrap/${{ github.event.inputs.ompi_version }} |
| 83 | + *.cache-to=type=gha,mode=max,scope=bootstrap/${{ github.event.inputs.ompi_version }} |
| 84 | + *.args.OMPI_VERSION=${{ github.event.inputs.ompi_version }} |
| 85 | + |
| 86 | + - name: Bootstrap the environment Dockerfile |
| 87 | + run: docker run -v ${GITHUB_WORKSPACE}/.github:/configs bootstrap |
| 88 | + |
| 89 | + - name: Build the environment |
| 90 | + uses: docker/bake-action@v5 |
| 91 | + with: |
| 92 | + files: .github/docker-compose.yml |
| 93 | + targets: env |
| 94 | + workdir: . |
| 95 | + pull: true |
| 96 | + set: | |
| 97 | + *.cache-from=type=gha,scope=env/${{ github.event.inputs.ompi_version }} |
| 98 | + *.cache-to=type=gha,mode=max,scope=env/${{ github.event.inputs.ompi_version }} |
| 99 | + env.tags=ghcr.io/sandialabs/fenix/env:${{ github.event.inputs.ompi_version }} |
| 100 | + env.output=type=registry,name=ghcr.io/sandialabs/fenix/env:${{ github.event.inputs.ompi_version }} |
0 commit comments