Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
158 changes: 51 additions & 107 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,27 @@ on:
pull_request:
branches: [ master, dev ]

env:
REGISTRY: ghcr.io
REPOSITORY: ${{ github.repository }}
IMAGES: >-
[{
'name': 'kafka-connect-transform-keyvalue',
'build_file': 'Dockerfile',
'authors': 'Pim van Nierop <pim@thehyve.nl>',
'description': 'Key-value transformation for Kafka Connect'
},{
'name': 'kafka-connect-transform-s3',
'build_file': 'Dockerfile.s3',
'authors': 'Pim van Nierop <pim@thehyve.nl>',
'description': 'Key-value transformation for Kafka Connect, with S3 connector loaded'
}]

jobs:
# Build and test the code
kotlin:
# The type of runner that the job will run on
runs-on: ubuntu-latest

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3

- uses: actions/setup-java@v3
Expand All @@ -34,45 +46,45 @@ jobs:
- name: Check
run: ./gradlew check

# Build and push tagged release backend docker image
dockerS3:
# The type of runner that the job will run on
prepare-matrix:
name: Prepare Matrix Output
permissions: {}
runs-on: ubuntu-latest
outputs:
images: ${{ steps.step1.outputs.matrix }}
steps:
- name: Create Matrix Variable
id: step1
run: echo "matrix=${{ env.IMAGES }}" >> $GITHUB_OUTPUT

env:
DOCKER_IMAGE: radarbase/kafka-connect-transform-s3
# Build and push tagged release backend docker image
docker:
needs: prepare-matrix
runs-on: ubuntu-latest
strategy:
matrix:
image: ${{ fromJson(needs.prepare-matrix.outputs.images ) }}
permissions:
contents: read
packages: write

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3

- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

# Add Docker labels and tags
- name: Docker meta
id: docker_meta
uses: docker/metadata-action@v4
with:
images: ${{ env.DOCKER_IMAGE }}

# Setup docker build environment
- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2

- name: Cache layers
id: cache-buildx
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-s3-${{ hashFiles('Dockerfile.s3', 'src/**', '*.gradle') }}
key: ${{ runner.os }}-buildx-s3-${{ hashFiles(matrix.image.build_file, 'src/**', '*.gradle') }}
restore-keys: |
${{ runner.os }}-buildx-s3-
${{ runner.os }}-buildx-
Expand All @@ -88,59 +100,17 @@ jobs:
echo "load-cache-from=type=local,src=/tmp/.buildx-cache-new" >> $GITHUB_OUTPUT
fi

- name: Build backend docker
uses: docker/build-push-action@v3
with:
context: .
file: ./Dockerfile.s3
platforms: linux/amd64,linux/arm64
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: ${{ steps.cache-parameters.outputs.cache-to }}
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.docker_meta.outputs.tags }}
# Use runtime labels from docker_meta_backend as well as fixed labels
labels: |
${{ steps.docker_meta.outputs.labels }}

# will use the internal cache from the previous build step, and load it into the current memory
- name: Build backend docker locally
uses: docker/build-push-action@v3
- name: Login to Container Registry
uses: docker/login-action@v2
with:
context: ./
file: ./Dockerfile.s3
cache-from: ${{ steps.cache-parameters.outputs.load-cache-from }}
load: true
tags: ${{ steps.docker_meta.outputs.tags }}
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Inspect docker image
run: docker image inspect ${{ env.DOCKER_IMAGE }}:${{ steps.docker_meta.outputs.version }}

# Temp fix
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
- name: Move docker build cache
if: steps.cache-buildx.outputs.cache-hit != 'true'
- name: Lowercase image name
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache

docker:
# The type of runner that the job will run on
runs-on: ubuntu-latest

env:
DOCKER_IMAGE: radarbase/kafka-connect-transform-keyvalue

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3

- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
echo "DOCKER_IMAGE=${REGISTRY}/${REPOSITORY,,}/${{ matrix.image.name }}"
echo "DOCKER_IMAGE=${REGISTRY}/${REPOSITORY,,}/${{ matrix.image.name }}" >>${GITHUB_ENV}

# Add Docker labels and tags
- name: Docker meta
Expand All @@ -149,57 +119,31 @@ jobs:
with:
images: ${{ env.DOCKER_IMAGE }}

# Setup docker build environment
- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Cache frontend layers
id: cache-buildx
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-generic-${{ hashFiles('Dockerfile', 'src/**', '*.gradle') }}
restore-keys: |
${{ runner.os }}-buildx-generic-
${{ runner.os }}-buildx-

- name: Cache parameters
id: cache-parameters
run: |
if [ "${{ steps.cache-buildx.outputs.cache-hit }}" = "true" ]; then
echo "cache-to=" >> $GITHUB_OUTPUT
echo "load-cache-from=type=local,src=/tmp/.buildx-cache" >> $GITHUB_OUTPUT
else
echo "cache-to=type=local,dest=/tmp/.buildx-cache-new,mode=max" >> $GITHUB_OUTPUT
echo "load-cache-from=type=local,src=/tmp/.buildx-cache-new" >> $GITHUB_OUTPUT
fi

- name: Build docker
- name: Build docker and optionally push
uses: docker/build-push-action@v3
with:
context: .
file: ${{ matrix.image.build_file }}
platforms: linux/amd64,linux/arm64
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: ${{ steps.cache-parameters.outputs.cache-to }}
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.docker_meta.outputs.tags }}
# Use runtime labels from docker_meta as well as fixed labels
labels: |
${{ steps.docker_meta.outputs.labels }}

- name: Build docker locally
- name: Build docker using cache and load
uses: docker/build-push-action@v3
with:
context: .
file: ${{ matrix.image.build_file }}
cache-from: ${{ steps.cache-parameters.outputs.load-cache-from }}
load: true
tags: ${{ steps.docker_meta.outputs.tags }}

- name: Inspect docker image
run: docker image inspect ${{ env.DOCKER_IMAGE }}:${{ steps.docker_meta.outputs.version }}
run: |
docker image inspect ${{ env.DOCKER_IMAGE }}:${{ steps.docker_meta.outputs.version }}

# Temp fix
# https://github.com/docker/build-push-action/issues/252
Expand Down
Loading
Loading