|
| 1 | +name: docker-image |
| 2 | +on: |
| 3 | + workflow_call: |
| 4 | + |
| 5 | +env: |
| 6 | + REGISTRY: ghcr.io |
| 7 | + # github.repository as <account>/<repo> |
| 8 | + IMAGE_NAME: LLNL/GPLaSDI/lasdi_env |
| 9 | + DOCKERPATH: docker |
| 10 | + |
| 11 | +jobs: |
| 12 | + docker-ci: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + name: "docker env" |
| 15 | + env: |
| 16 | + DOCKERPATH: docker |
| 17 | + steps: |
| 18 | + - name: test command |
| 19 | + run: echo "docker-ci command" |
| 20 | + - uses: actions/checkout@v4 |
| 21 | + with: |
| 22 | + fetch-depth: 0 |
| 23 | + - name: Set up QEMU |
| 24 | + uses: docker/setup-qemu-action@v3 |
| 25 | + - name: Set up Docker Buildx |
| 26 | + uses: docker/setup-buildx-action@v3 |
| 27 | + - uses: Ana06/get-changed-files@v2.2.0 |
| 28 | + id: files |
| 29 | + - name: DockerPATH configuration |
| 30 | + run: echo "DOCKERPATH=$DOCKERPATH" |
| 31 | + - name: DockerPATH - check if files in docker path changed |
| 32 | + if: contains(steps.files.outputs.all,env.DOCKERPATH) || contains(steps.files.outputs.all,'docker.yml') |
| 33 | + run: | |
| 34 | + echo "CI container needs rebuilding..." |
| 35 | + echo "CI_NEEDS_REBUILD=true" >> $GITHUB_ENV |
| 36 | + - name: Log into registry ${{ env.REGISTRY }} |
| 37 | + if: env.CI_NEEDS_REBUILD |
| 38 | + uses: docker/login-action@v3 |
| 39 | + with: |
| 40 | + registry: ${{ env.REGISTRY }} |
| 41 | + username: ${{ github.actor }} |
| 42 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 43 | + - name: Extract metadata (tags, labels) for Docker |
| 44 | + id: meta |
| 45 | + if: env.CI_NEEDS_REBUILD |
| 46 | + uses: docker/metadata-action@v4 |
| 47 | + with: |
| 48 | + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
| 49 | + tags: type=sha |
| 50 | + flavor: latest=true |
| 51 | + - name: Build Container motd |
| 52 | + if: env.CI_NEEDS_REBUILD |
| 53 | + run: | |
| 54 | + echo "#!/bin/bash" > ${{env.DOCKERPATH}}/motd.sh |
| 55 | + echo "echo --------------------------" >> ${{env.DOCKERPATH}}/motd.sh |
| 56 | + echo "echo lasdi_env/CI Development Container" >> ${{env.DOCKERPATH}}/motd.sh |
| 57 | + echo "echo \"Revision: `echo ${GITHUB_SHA} | cut -c1-8`\"" >> ${{env.DOCKERPATH}}/motd.sh |
| 58 | + echo "echo --------------------------" >> ${{env.DOCKERPATH}}/motd.sh |
| 59 | + chmod 755 ${{env.DOCKERPATH}}/motd.sh |
| 60 | + cat ${{env.DOCKERPATH}}/motd.sh |
| 61 | + - name: Docker Image - Build and push |
| 62 | + if: env.CI_NEEDS_REBUILD |
| 63 | + uses: docker/build-push-action@v5 |
| 64 | + with: |
| 65 | + push: true |
| 66 | + context: ${{ env.DOCKERPATH }} |
| 67 | + tags: ${{ steps.meta.outputs.tags }} |
| 68 | + # platforms: linux/amd64,linux/arm64 |
| 69 | + platforms: linux/amd64 |
0 commit comments