From 1aad0497c5f19b8132fe5ecf4a80e1d16a6516d8 Mon Sep 17 00:00:00 2001 From: Damien Degois Date: Mon, 14 Oct 2024 21:18:33 +0200 Subject: [PATCH] Add github action build --- .github/workflows/release.yml | 70 ++++++++++++++++++++++++++++++++ Dockerfile | 2 + README.md | 4 +- glci-example/templates/build.yml | 2 +- 4 files changed, 75 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..8e6a598 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,70 @@ +name: "Build OCI Image" + +on: + push: + tags: + - 'v[0-9]+.[0-9]+.[0-9]+' + - 'v[0-9]+.[0-9]+.[0-9]+-*' + workflow_dispatch: + +jobs: + build-image: + name: "Build OCI image" + runs-on: ubuntu-latest + permissions: + contents: write + packages: write + attestations: write + id-token: write + steps: + - uses: actions/checkout@v4 + - name: Define TARGETS + run: | + #REPOS="quay.io/${{ vars.QUAYIO_USERNAME }}/kaniko-w-ecr-repo-creator ghcr.io/${{ github.repository }}" + REPOS="quay.io/${{ vars.QUAYIO_USERNAME }}/kaniko-w-ecr-repo-creator ghcr.io/babs/kaniko-w-ecr-repo-creator" + IMG_TAGS="latest" + + if [ ${GITHUB_REF_TYPE:-} == 'tag' -a -n "$(echo $GITHUB_REF_NAME | grep -iE '^v[0-9]+\.[0-9]+\.[0-9]+(-[a-z0-9.-]+)?$')" ]; then + TAG=${GITHUB_REF_NAME#v} + RELEASE="" + case "$TAG" in + *-*) + RELEASE="-${TAG#*-}" + ;; + esac + SEMVER_CORE="${TAG%%-*}" + IMG_TAGS="${IMG_TAGS} $TAG ${SEMVER_CORE%.*}${RELEASE} ${SEMVER_CORE%%.*}${RELEASE}" + fi + + echo "Targets:" + TARGETS="" + for REPO in $REPOS; do + for IMG_TAG in $IMG_TAGS; do + TARGETS="${TARGETS},${REPO}:${IMG_TAG}" + echo "- ${REPO}:${IMG_TAG}" + done + done + echo TARGETS=${TARGETS#,} >>$GITHUB_ENV + + - uses: docker/setup-buildx-action@v2 + + - name: Login to GitHub Container Registry + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Login to Quay.io + uses: docker/login-action@v2 + with: + registry: quay.io + username: ${{ secrets.QUAYIO_ROBOT_ACCOUNTNAME }} + password: ${{ secrets.QUAYIO_ROBOT_TOKEN }} + + - name: Build and push + uses: docker/build-push-action@v3 + with: + context: . + push: true + tags: ${{ env.TARGETS }} diff --git a/Dockerfile b/Dockerfile index 7a006b5..2474f29 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,6 +17,8 @@ RUN set -xe \ FROM gcr.io/kaniko-project/executor:${KANIKO_VERSION}-debug AS final-stage +LABEL org.opencontainers.image.source=https://github.com/babs/ecr-repo-creator + COPY --from=ghcr.io/jqlang/jq /jq /usr/local/bin/ COPY --from=golang-am8-envsubst /go/bin/envsubst /usr/local/bin/ COPY --from=build-stage /app/ecr-repo-creator /usr/local/bin/ diff --git a/README.md b/README.md index 40a258f..2310951 100644 --- a/README.md +++ b/README.md @@ -41,8 +41,8 @@ For Kaniko version: https://github.com/GoogleContainerTools/kaniko/releases For Golang version: https://hub.docker.com/_/golang -A prebuilt image of `kaniko` with `ecr-repo-creator` and `jq` is available at [beardedbabs/kaniko-w-ecr-repo-creator](https://hub.docker.com/r/beardedbabs/kaniko-w-ecr-repo-creator) +A prebuilt image of `kaniko` with `ecr-repo-creator`, `jq` and `envsubst` is available at [ghcr.io/babs/kaniko-w-ecr-repo-creator](https://github.com/babs/ecr-repo-creator/pkgs/container/kaniko-w-ecr-repo-creator) ```bash -docker pull beardedbabs/kaniko-w-ecr-repo-creator:latest +docker pull ghcr.io/babs/kaniko-w-ecr-repo-creator:1 ``` \ No newline at end of file diff --git a/glci-example/templates/build.yml b/glci-example/templates/build.yml index c5aef5c..c685212 100644 --- a/glci-example/templates/build.yml +++ b/glci-example/templates/build.yml @@ -111,7 +111,7 @@ variables: $[[ inputs.job_name ]]: stage: $[[ inputs.stage ]] image: - name: beardedbabs/kaniko-w-ecr-repo-creator:latest + name: ghcr.io/babs/kaniko-w-ecr-repo-creator:1 entrypoint: [""] tags: - $[[ inputs.runner_tags ]]