diff --git a/.github/workflows/container.yml b/.github/workflows/container.yml new file mode 100644 index 000000000..6d7ff5611 --- /dev/null +++ b/.github/workflows/container.yml @@ -0,0 +1,57 @@ +name: Create and publish a container image + +on: + push: + # Publish main branch as `develop` image + branches: + - main + - master + + # Publish tags as versioned release and `latest` image + tags: + - '*' + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + build-and-push-image: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Log in to registry + run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin + + - name: Build and push container image + run: | + # Image name may contain only lowercase letters + IMAGE_ID=$(echo ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | tr '[A-Z]' '[a-z]') + + # Strip git ref prefix from version + VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,') + # If not tag, then use `develop` as image tag + [ "$VERSION" == main -o "$VERSION" == master ] && VERSION=develop + + echo IMAGE_ID=$IMAGE_ID + echo VERSION=$VERSION + + docker build . --file container/Dockerfile \ + --build-arg "CREATED=$(date --rfc-3339=seconds)" \ + --build-arg "VERSION=$(git describe --always)" \ + --build-arg "COMMIT=$(git rev-parse -q --verify HEAD^{commit})" \ + --tag $IMAGE_ID:$VERSION + + docker push $IMAGE_ID:$VERSION + + if [[ "${{ github.ref }}" == "refs/tags/"* ]]; + then + docker tag $IMAGE_ID:$VERSION $IMAGE_ID:latest + docker push $IMAGE_ID:latest + fi diff --git a/README.rst b/README.rst index 1c40b3995..c5a7b5cea 100644 --- a/README.rst +++ b/README.rst @@ -50,7 +50,7 @@ Setup Using Docker ------------ -To get you up and running with the latest release of Karapace, a docker setup is available:: +To get you up and running with the latest build of Karapace, a docker setup is available:: docker-compose -f ./container/docker-compose.yml up -d diff --git a/container/docker-compose.yml b/container/docker-compose.yml index b8d4443c9..0d8f1f2e9 100644 --- a/container/docker-compose.yml +++ b/container/docker-compose.yml @@ -56,7 +56,7 @@ services: KAFKA_ZOOKEEPER_CONNECT: "zookeeper:2181" karapace-registry: - image: aivenoy/karapace:latest + image: ghcr.io/aiven/karapace:develop entrypoint: - /bin/bash - /opt/karapace/start.sh @@ -78,7 +78,7 @@ services: KARAPACE_COMPATIBILITY: FULL karapace-rest: - image: aivenoy/karapace:latest + image: ghcr.io/aiven/karapace:develop entrypoint: - /bin/bash - /opt/karapace/start.sh