wip github workflows updates #1
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: Builder | ||
| on: | ||
| workflow_call: | ||
| inputs: | ||
| context: | ||
| description: 'Effective Working Directory' | ||
| required: true | ||
| type: string | ||
| default: "./" | ||
| image_name: | ||
| description: 'Image Name' | ||
| required: true | ||
| type: string | ||
| github_username: | ||
| description: 'Github Container Registry Username' | ||
| required: true | ||
| type: string | ||
| dockerhub_username: | ||
| description: 'Dockerhub Container Registry Username' | ||
| required: false | ||
| type: string | ||
| dockerhub_organization: | ||
| description: 'Dockerhub Container Registry Organization' | ||
| required: false | ||
| type: string | ||
| default: bcgovimages | ||
| secrets: | ||
| github_token: | ||
| description: 'Github Container Registry Authorization Token' | ||
| required: true | ||
| dockerhub_token: | ||
| description: 'Dockerhub Container Registry Authorization Token' | ||
| required: false | ||
| outputs: | ||
| image_tag: | ||
| description: 'Docker image tag' | ||
| value: ${{ jobs.builder.outputs.image_tag }} | ||
| jobs: | ||
| builder: | ||
| name: Builder | ||
| permissions: | ||
| packages: write # for docker/build-push-action to push images to GitHub Container Registry | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 10 | ||
| outputs: | ||
| image_tag: ${{ steps.meta.outputs.version }} | ||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v6 | ||
| - name: Parse Input Values | ||
| shell: bash | ||
| run: | | ||
| echo "GH_USERNAME=$(tr '[:upper:]' '[:lower:]' <<< '${{ inputs.github_username }}')" >> $GITHUB_ENV | ||
| echo "HAS_DOCKERHUB=${{ inputs.dockerhub_username != '' && secrets.dockerhub_token != '' }}" >> $GITHUB_ENV | ||
| - name: Login to Github Container Registry | ||
| uses: docker/login-action@v4 | ||
| with: | ||
| registry: ghcr.io | ||
| username: ${{ env.GH_USERNAME }} | ||
| password: ${{ secrets.github_token }} | ||
| - name: Login to Dockerhub Container Registry | ||
| if: env.HAS_DOCKERHUB == 'true' | ||
| uses: docker/login-action@v4 | ||
| with: | ||
| registry: docker.io | ||
| username: ${{ inputs.dockerhub_username }} | ||
| password: ${{ secrets.dockerhub_token }} | ||
| - name: Prepare Container Metadata tags | ||
| id: meta | ||
| uses: docker/metadata-action@v6 | ||
| with: | ||
| images: | | ||
| ghcr.io/${{ env.GH_USERNAME }}/${{ inputs.image_name }} | ||
| docker.io/${{ inputs.dockerhub_organization }}/${{ inputs.image_name }},enable=${{ env.HAS_DOCKERHUB }} | ||
| # Always updates the 'latest' tag | ||
| flavor: | | ||
| latest=true | ||
| # Creates tags based off of branch names and semver tags | ||
| tags: | | ||
| type=ref,event=branch | ||
| type=ref,event=pr | ||
| type=semver,pattern={{version}} | ||
| type=semver,pattern={{major}}.{{minor}} | ||
| type=semver,pattern={{major}} | ||
| type=sha | ||
| - name: Build and Push to Container Registry | ||
| id: builder | ||
| uses: docker/build-push-action@v7 | ||
| with: | ||
| context: ${{ inputs.context }} | ||
| push: true | ||
| tags: ${{ steps.meta.outputs.tags }} | ||
| labels: ${{ steps.meta.outputs.labels }} | ||
| annotations: ${{ steps.meta.outputs.annotations }} | ||
| build-args: | | ||
| GIT_COMMIT=${{ github.sha }} | ||
| - name: Inspect Docker Image | ||
| shell: bash | ||
| run: | | ||
| docker image inspect ghcr.io/${{ env.GH_USERNAME }}/${{ inputs.image_name }}:latest | ||