From 894070361653805f88e378cbbe30049c7e2b6408 Mon Sep 17 00:00:00 2001 From: Marko Bocevski Date: Sat, 16 Jan 2021 02:15:03 +0100 Subject: [PATCH] Add automatic push to GHCR and dockerhub on push to master and set GHCR default --- .github/workflows/master_merge.yml | 241 ++++++++++++++++++++++++ .github/workflows/pr_checks.yml | 1 - Readme.md | 12 +- compose/docker-compose.yml | 4 +- examples/harvest/Dockerfile | 4 +- examples/harvest/docker-compose.yml | 2 +- examples/s3filestore/Dockerfile | 4 +- examples/s3filestore/docker-compose.yml | 2 +- 8 files changed, 257 insertions(+), 13 deletions(-) create mode 100644 .github/workflows/master_merge.yml diff --git a/.github/workflows/master_merge.yml b/.github/workflows/master_merge.yml new file mode 100644 index 0000000..74af5af --- /dev/null +++ b/.github/workflows/master_merge.yml @@ -0,0 +1,241 @@ +name: Build and push docker images + +on: + push: + branches: master + +jobs: + build-ckan-2-9: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Login to DockerHub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} + + name: Login to GitHub Container Registry + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.CR_PAT }} + + - name: Cache Docker layers + uses: actions/cache@v2 + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-buildx-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-buildx + + - name: Get docker tag for Alpine image + id: alpine + run: | + echo "::set-output name=IMAGE_TAG::$(awk -F '=' '/IMAGE_TAG/{print $2}' ./images/ckan/2.9/Dockerfile)" + + - name: Build and push CKAN 2.9 alpine + uses: docker/build-push-action@v2 + with: + context: ./images/ckan/2.9 + file: ./images/ckan/2.9/Dockerfile + push: true + tags: | + keitaro/ckan:${{ steps.alpine.outputs.IMAGE_TAG }} + ghcr.io/keitaroinc/ckan:${{ steps.alpine.outputs.IMAGE_TAG }} + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,mode=max,dest=/tmp/.buildx-cache + + - name: Get docker tag for Ubuntu image + id: ubuntu + run: | + echo "::set-output name=IMAGE_TAG::$(awk -F '=' '/IMAGE_TAG/{print $2}' ./images/ckan/2.9/Dockerfile.focal)" + + - name: Build and push CKAN 2.9 ubuntu + uses: docker/build-push-action@v2 + with: + context: ./images/ckan/2.9 + file: ./images/ckan/2.9/Dockerfile.focal + push: true + tags: | + keitaro/ckan:${{ steps.ubuntu.outputs.IMAGE_TAG }} + ghcr.io/keitaroinc/ckan:${{ steps.ubuntu.outputs.IMAGE_TAG }} + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,mode=max,dest=/tmp/.buildx-cache + + build-ckan-2-8: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Login to DockerHub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} + + name: Login to GitHub Container Registry + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.CR_PAT }} + + - name: Cache Docker layers + uses: actions/cache@v2 + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-buildx-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-buildx- + + - name: Get docker tag for Alpine image + id: alpine + run: | + echo "::set-output name=IMAGE_TAG::$(awk -F '=' '/IMAGE_TAG/{print $2}' ./images/ckan/2.8/Dockerfile)" + + - name: Build and push CKAN 2.8 alpine + uses: docker/build-push-action@v2 + with: + context: ./images/ckan/2.8 + file: ./images/ckan/2.8/Dockerfile + push: true + tags: | + keitaro/ckan:${{ steps.alpine.outputs.IMAGE_TAG }} + ghcr.io/keitaroinc/ckan:${{ steps.alpine.outputs.IMAGE_TAG }} + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,mode=max,dest=/tmp/.buildx-cache + + - name: Get docker tag for Ubuntu image + id: ubuntu + run: | + echo "::set-output name=IMAGE_TAG::$(awk -F '=' '/IMAGE_TAG/{print $2}' ./images/ckan/2.8/Dockerfile.focal)" + + - name: Build and push CKAN 2.8 ubuntu + uses: docker/build-push-action@v2 + with: + context: ./images/ckan/2.8 + file: ./images/ckan/2.8/Dockerfile.focal + push: true + tags: | + keitaro/ckan:${{ steps.ubuntu.outputs.IMAGE_TAG }} + ghcr.io/keitaroinc/ckan:${{ steps.ubuntu.outputs.IMAGE_TAG }} + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,mode=max,dest=/tmp/.buildx-cache + + build-ckan-2-7: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Login to DockerHub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} + + name: Login to GitHub Container Registry + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.CR_PAT }} + + - name: Cache Docker layers + uses: actions/cache@v2 + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-buildx-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-buildx- + + - name: Get docker tag for Alpine image + id: alpine + run: | + echo "::set-output name=IMAGE_TAG::$(awk -F '=' '/IMAGE_TAG/{print $2}' ./images/ckan/2.7/Dockerfile)" + + - name: Build and push CKAN 2.7 alpine + uses: docker/build-push-action@v2 + with: + context: ./images/ckan/2.7 + file: ./images/ckan/2.7/Dockerfile + push: true + tags: | + keitaro/ckan:${{ steps.alpine.outputs.IMAGE_TAG }} + ghcr.io/keitaroinc/ckan:${{ steps.alpine.outputs.IMAGE_TAG }} + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,mode=max,dest=/tmp/.buildx-cache + + - name: Get docker tag for Ubuntu image + id: ubuntu + run: | + echo "::set-output name=IMAGE_TAG::$(awk -F '=' '/IMAGE_TAG/{print $2}' ./images/ckan/2.7/Dockerfile.focal)" + + - name: Build CKAN 2.7 ubuntu + uses: docker/build-push-action@v2 + with: + context: ./images/ckan/2.7 + file: ./images/ckan/2.7/Dockerfile.focal + push: true + tags: | + keitaro/ckan:${{ steps.ubuntu.outputs.IMAGE_TAG }} + ghcr.io/keitaroinc/ckan:${{ steps.ubuntu.outputs.IMAGE_TAG }} + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,mode=max,dest=/tmp/.buildx-cache + + build-ckan-datapusher: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Login to DockerHub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} + + name: Login to GitHub Container Registry + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.CR_PAT }} + + - name: Cache Docker layers + uses: actions/cache@v2 + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-buildx-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-buildx- + + - name: Get docker tag for datapusher image + id: datapusher + run: | + echo "::set-output name=IMAGE_TAG::$(awk -F '=' '/IMAGE_TAG/{print $2}' ./images/datapusher/Dockerfile)" + + - name: Build and push CKAN datapusher + uses: docker/build-push-action@v2 + with: + context: ./images/datapusher + file: ./images/datapusher/Dockerfile + push: true + tags: | + keitaro/datapusher:${{ steps.datapusher.outputs.IMAGE_TAG }} + ghcr.io/keitaroinc/datapusher:${{ steps.datapusher.outputs.IMAGE_TAG }} + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,mode=max,dest=/tmp/.buildx-cache diff --git a/.github/workflows/pr_checks.yml b/.github/workflows/pr_checks.yml index 54d94d3..34a1665 100644 --- a/.github/workflows/pr_checks.yml +++ b/.github/workflows/pr_checks.yml @@ -3,7 +3,6 @@ name: PR Checks on: pull_request: branches: master - workflow_dispatch: jobs: build-ckan-2-9: diff --git a/Readme.md b/Readme.md index ff95437..2ef79ae 100644 --- a/Readme.md +++ b/Readme.md @@ -8,6 +8,10 @@ We build and publish docker images built using this repository to Dockerhub: - [CKAN docker images](https://hub.docker.com/r/keitaro/ckan). - [Datapusher docker images](https://hub.docker.com/r/keitaro/ckan-datapusher) +and Github Container Registry: +- [CKAN docker images on GHCR](https://github.com/orgs/keitaroinc/packages/container/package/ckan) +- [Datapusher docker images on GHCR](https://github.com/orgs/keitaroinc/packages/container/package/datapusher) + Looking to run CKAN on Kubernetes? Check out our [CKAN Helm Chart](https://github.com/keitaroinc/ckan-helm)! ## Overview @@ -40,7 +44,7 @@ We recommend to use a multi-stage approach to extend the docker images that we p ################### ### Extensions #### ################### -FROM keitaro/ckan:2.9.1 as extbuild +FROM ghcr.io/keitaroinc/ckan:2.9.1 as extbuild # Switch to the root user USER root @@ -54,7 +58,7 @@ RUN pip wheel --wheel-dir=/wheels git+https://github.com/acmecorp/ckanext-acme@0 ############ ### MAIN ### ############ -FROM keitaro/ckan:2.9.1 +FROM ghcr.io/keitaroinc/ckan:2.9.1 # Add the custom extensions to the plugins list ENV CKAN__PLUGINS envvars image_view text_view recline_view datastore datapusher acme @@ -84,9 +88,9 @@ You can add scripts to CKAN custom images and copy them to the *docker-afterinit ## Build To build a CKAN image run: ```sh -docker build --tag keitaro/ckan:2.9.1 images/ckan/2.9 +docker build --tag ghcr.io/keitaroinc/ckan:2.9.1 images/ckan/2.9 ``` -The –-tag keitaro/ckan:2.9.1 flag sets the image name to ketiaro/ckan:2.9.1 and 'images/ckan/2.9' at the end tells docker build to use the context into the specified directory where the Dockerfile and related contents are. +The –-tag ghcr.io/keitaroinc/ckan:2.9.1 flag sets the image name to ghcr.io/keitaroinc/ckan:2.9.1 and 'images/ckan/2.9' at the end tells docker build to use the context into the specified directory where the Dockerfile and related contents are. ## Upload to DockerHub >*It's recommended to upload built images to DockerHub* diff --git a/compose/docker-compose.yml b/compose/docker-compose.yml index 675fbf8..c5c17b6 100644 --- a/compose/docker-compose.yml +++ b/compose/docker-compose.yml @@ -9,7 +9,7 @@ volumes: services: ckan: container_name: ckan - image: keitaro/ckan:${CKAN_VERSION} + image: ghcr.io/keitaroinc/ckan:${CKAN_VERSION} networks: - frontend - backend @@ -34,7 +34,7 @@ services: datapusher: container_name: datapusher - image: keitaro/ckan-datapusher:${DATAPUSHER_VERSION} + image: ghcr.io/keitaroinc/datapusher:${DATAPUSHER_VERSION} networks: - frontend - backend diff --git a/examples/harvest/Dockerfile b/examples/harvest/Dockerfile index df3202f..49a345b 100644 --- a/examples/harvest/Dockerfile +++ b/examples/harvest/Dockerfile @@ -1,7 +1,7 @@ ################### ### Extensions #### ################### -FROM keitaro/ckan:2.9.1 as extbuild +FROM ghcr.io/keitaroinc/ckan:2.9.1 as extbuild # Locations and tags, please use specific tags or revisions ENV HARVEST_GIT_URL=https://github.com/ckan/ckanext-harvest @@ -28,7 +28,7 @@ USER ckan ############ ### MAIN ### ############ -FROM keitaro/ckan:2.9.1 +FROM ghcr.io/keitaroinc/ckan:2.9.1 LABEL maintainer="Keitaro Inc " diff --git a/examples/harvest/docker-compose.yml b/examples/harvest/docker-compose.yml index fc2f961..7ad2d70 100644 --- a/examples/harvest/docker-compose.yml +++ b/examples/harvest/docker-compose.yml @@ -133,7 +133,7 @@ services: datapusher: container_name: datapusher - image: keitaro/ckan-datapusher:${DATAPUSHER_VERSION} + image: ghcr.io/keitaroinc/datapusher:${DATAPUSHER_VERSION} networks: - frontend - backend diff --git a/examples/s3filestore/Dockerfile b/examples/s3filestore/Dockerfile index 7e45e25..14d3d8d 100644 --- a/examples/s3filestore/Dockerfile +++ b/examples/s3filestore/Dockerfile @@ -1,7 +1,7 @@ ################### ### Extensions #### ################### -FROM keitaro/ckan:2.8.6 as extbuild +FROM ghcr.io/keitaroinc/ckan:2.8.6 as extbuild # Locations and tags, please use specific tags or revisions ENV S3FILESTORE_GIT_URL=https://github.com/keitaroinc/ckanext-s3filestore @@ -20,7 +20,7 @@ USER ckan ############ ### MAIN ### ############ -FROM keitaro/ckan:2.8.6 +FROM ghcr.io/keitaroinc/ckan:2.8.6 LABEL maintainer="Keitaro Inc " diff --git a/examples/s3filestore/docker-compose.yml b/examples/s3filestore/docker-compose.yml index a2eb487..45d8359 100644 --- a/examples/s3filestore/docker-compose.yml +++ b/examples/s3filestore/docker-compose.yml @@ -33,7 +33,7 @@ services: datapusher: container_name: datapusher - image: keitaro/ckan-datapusher:${DATAPUSHER_VERSION} + image: ghcr.io/keitaroinc/datapusher:${DATAPUSHER_VERSION} networks: - frontend - backend