|
| 1 | +# SPDX-FileCopyrightText: 2022 Dusan Mijatovic (dv4all) |
| 2 | +# SPDX-FileCopyrightText: 2022 dv4all |
| 3 | +# SPDX-FileCopyrightText: 2024 Ewan Cahen (Netherlands eScience Center) <e.cahen@esciencecenter.nl> |
| 4 | +# SPDX-FileCopyrightText: 2024 Netherlands eScience Center |
| 5 | +# |
| 6 | +# SPDX-License-Identifier: Apache-2.0 |
| 7 | + |
| 8 | +name: reusable ghcr.io module |
| 9 | + |
| 10 | +on: |
| 11 | + workflow_call: |
| 12 | + inputs: |
| 13 | + ghcr_user: |
| 14 | + required: true |
| 15 | + description: User for logging to ghcr.io (use github.actor) |
| 16 | + type: string |
| 17 | + base_image_name: |
| 18 | + required: true |
| 19 | + description: Base image name incl. ghcr.io |
| 20 | + type: string |
| 21 | + image_tag: |
| 22 | + required: true |
| 23 | + description: Image tag (version) |
| 24 | + type: string |
| 25 | + dockerfile: |
| 26 | + required: true |
| 27 | + description: Location and name of docker file |
| 28 | + type: string |
| 29 | + docker_context: |
| 30 | + required: true |
| 31 | + description: Docker context for the build command |
| 32 | + type: string |
| 33 | + secrets: |
| 34 | + token: |
| 35 | + required: true |
| 36 | + outputs: |
| 37 | + image_created: |
| 38 | + description: Full image name after upload to ghcr.io |
| 39 | + value: ${{jobs.build_and_push.outputs.image_build}} |
| 40 | + image_uploaded: |
| 41 | + description: Confirmation that image is uploaded to ghcr.io |
| 42 | + value: ${{jobs.build_and_push.outputs.image_pushed}} |
| 43 | + |
| 44 | +jobs: |
| 45 | + build_and_push: |
| 46 | + name: build and push image |
| 47 | + runs-on: ubuntu-22.04 |
| 48 | + outputs: |
| 49 | + image_build: ${{steps.build_image.outputs.image_build}} |
| 50 | + image_pushed: ${{steps.build_image.outputs.image_pushed}} |
| 51 | + steps: |
| 52 | + - name: checkout |
| 53 | + # https://github.com/actions/checkout |
| 54 | + uses: actions/checkout@v4 |
| 55 | + - name: build |
| 56 | + id: build_image |
| 57 | + run: | |
| 58 | + IMAGE_TAG_VERSION=${{inputs.base_image_name}}:${{inputs.image_tag}} |
| 59 | + IMAGE_TAG_LASTEST=${{inputs.base_image_name}}:latest |
| 60 | + echo image_tag_version $IMAGE_TAG_VERSION |
| 61 | + docker build -t $IMAGE_TAG_VERSION -t $IMAGE_TAG_LASTEST -f ${{inputs.dockerfile}} ${{inputs.docker_context}} |
| 62 | + echo "{image_build}={$IMAGE_TAG_VERSIONvalue}" >> $GITHUB_OUTPUT |
| 63 | + - name: push to ghcr.io |
| 64 | + id: push_image |
| 65 | + run: | |
| 66 | + echo login |
| 67 | + echo "${{secrets.token}}" | docker login https://ghcr.io -u ${{inputs.ghcr_user}} --password-stdin |
| 68 | + echo push auth image with all tags |
| 69 | + docker push ${{inputs.base_image_name}} --all-tags |
| 70 | + echo "{image_build}={$IMAGE_TAG_VERSIONvalue}" >> $GITHUB_OUTPUT |
0 commit comments