|
| 1 | +name: Build container image |
| 2 | +on: |
| 3 | + schedule: |
| 4 | + - cron: '5 10 1 * *' # 10:05am UTC 1st day of every month |
| 5 | + push: |
| 6 | + branches: |
| 7 | + - master |
| 8 | + paths-ignore: |
| 9 | + - '**/README.md' |
| 10 | + workflow_dispatch: |
| 11 | + |
| 12 | +env: |
| 13 | + IMAGE_DESC: "Arch Linux (Botany Distrobox)" |
| 14 | + IMAGE_LOGO_URL: "https://botany.pl/images/Layout/logo.svg" |
| 15 | + IMAGE_NAME: "${{ github.event.repository.name }}" |
| 16 | + DEFAULT_TAG: "latest" |
| 17 | + |
| 18 | +concurrency: |
| 19 | + group: ${{ github.workflow }}-${{ github.ref || github.run_id }}-${{ inputs.brand_name}}-${{ inputs.stream_name }} |
| 20 | + cancel-in-progress: true |
| 21 | + |
| 22 | +jobs: |
| 23 | + build_push: |
| 24 | + name: Build and push image |
| 25 | + runs-on: ubuntu-24.04 |
| 26 | + |
| 27 | + permissions: |
| 28 | + contents: read |
| 29 | + packages: write |
| 30 | + id-token: write |
| 31 | + |
| 32 | + steps: |
| 33 | + - name: Prepare environment |
| 34 | + run: | |
| 35 | + # Lowercase the image uri |
| 36 | + echo "IMAGE_NAME=${IMAGE_NAME,,}" >> ${GITHUB_ENV} |
| 37 | +
|
| 38 | + - name: Checkout |
| 39 | + uses: actions/checkout@v6 |
| 40 | + |
| 41 | + - name: Get current date |
| 42 | + id: date |
| 43 | + run: | |
| 44 | + # This generates a timestamp like what is defined on the ArtifactHub documentation |
| 45 | + # E.G: 2022-02-08T15:38:15Z' |
| 46 | + # https://artifacthub.io/docs/topics/repositories/container-images/ |
| 47 | + # https://linux.die.net/man/1/date |
| 48 | + echo "date=$(date -u +%Y\-%m\-%d\T%H\:%M\:%S\Z)" >> $GITHUB_OUTPUT |
| 49 | + echo "date_short=$(date -u +%Y%m%d)" >> $GITHUB_OUTPUT |
| 50 | +
|
| 51 | + # Image metadata for https://artifacthub.io/ - This is optional but is highly recommended so we all can get a index of all the custom images |
| 52 | + # The metadata by itself is not going to do anything, you choose if you want your image to be on ArtifactHub or not. |
| 53 | + - name: Image Metadata |
| 54 | + uses: docker/metadata-action@v5 |
| 55 | + id: metadata |
| 56 | + with: |
| 57 | + # This generates all the tags for your image, you can add custom tags here too! |
| 58 | + # Default tags are "$DEFAULT_TAG" and "$DEFAULT_TAG.$date". |
| 59 | + tags: | |
| 60 | + type=raw,value=${{ env.DEFAULT_TAG }} |
| 61 | + labels: | |
| 62 | + io.artifacthub.package.readme-url=https://raw.githubusercontent.com/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}/refs/heads/main/README.md |
| 63 | + org.opencontainers.image.created=${{ steps.date.outputs.date }} |
| 64 | + org.opencontainers.image.description=${{ env.IMAGE_DESC }} |
| 65 | + org.opencontainers.image.documentation=https://raw.githubusercontent.com/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}/refs/heads/main/README.md |
| 66 | + org.opencontainers.image.source=https://github.com/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}/blob/main/Containerfile |
| 67 | + org.opencontainers.image.title=${{ env.IMAGE_NAME }} |
| 68 | + org.opencontainers.image.url=https://github.com/${{ github.repository_owner }}/${{ env.IMAGE_NAME }} |
| 69 | + org.opencontainers.image.vendor=${{ github.repository_owner }} |
| 70 | + org.opencontainers.image.version=${{ env.DEFAULT_TAG }}.{{date 'YYYYMMDD'}} |
| 71 | + org.opencontainers.image.revision=${{ github.sha }} |
| 72 | + io.artifacthub.package.deprecated=false |
| 73 | + io.artifacthub.package.logo-url=${{ env.IMAGE_LOGO_URL }} |
| 74 | + io.artifacthub.package.prerelease=false |
| 75 | + sep-tags: " " |
| 76 | + sep-annotations: " " |
| 77 | + |
| 78 | + - name: Build Image |
| 79 | + id: build_image |
| 80 | + uses: redhat-actions/buildah-build@v2 |
| 81 | + with: |
| 82 | + containerfiles: | |
| 83 | + ./Containerfile |
| 84 | + image: ${{ env.IMAGE_NAME }} |
| 85 | + tags: ${{ steps.metadata.outputs.tags }} |
| 86 | + labels: ${{ steps.metadata.outputs.labels }} |
| 87 | + oci: true |
| 88 | + extra-args: | |
| 89 | + --security-opt=seccomp=unconfined |
| 90 | +
|
| 91 | + - name: Push to private registry |
| 92 | + uses: redhat-actions/push-to-registry@v2 |
| 93 | + if: github.event_name != 'pull_request' && github.ref == format('refs/heads/{0}', github.event.repository.default_branch) |
| 94 | + env: |
| 95 | + REGISTRY_USER: ${{ github.actor }} |
| 96 | + REGISTRY_PASSWORD: ${{ github.token }} |
| 97 | + with: |
| 98 | + registry: ${{ secrets.IMAGE_REGISTRY }} |
| 99 | + image: ${{ env.IMAGE_NAME }} |
| 100 | + tags: ${{ steps.metadata.outputs.tags }} |
| 101 | + username: ${{ secrets.REGISTRY_USER }} |
| 102 | + password: ${{ secrets.REGISTRY_PASSWORD }} |
| 103 | + extra-args: | |
| 104 | + --disable-content-trust |
| 105 | + --compression-format=zstd:chunked |
| 106 | + --force-compression=true |
0 commit comments