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
22 changes: 22 additions & 0 deletions .github/actions/docker-image-cache-restore/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Restore cached Docker image
description: Restore cached Docker image
inputs:
key:
description: The cache key
required: true
sha:
description: Commit SHA
required: true
default: ${{ github.sha }}

runs:
using: composite
steps:
- name: Download Docker image artifact
uses: actions/download-artifact@v5
with:
name: docker-custom-python-${{ inputs.key }}-${{ inputs.sha }}
path: /tmp
- name: Load Docker image
shell: bash
run: docker load --input /tmp/docker-custom-python-${{ inputs.key }}.tar
50 changes: 50 additions & 0 deletions .github/actions/docker-push/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Push to Registries
description: Push Docker image to multiple registries
inputs:
imageCacheKey:
description: The image cache key (Used to construct artifact name)
required: true
sourceImage:
description: The source image name
required: true
sourceTag:
description: The source image tag
required: true
default: latest
targetImage:
description: The target image name
required: true
targetTag:
description: The target image tag
required: true
acrRegistry:
description: ACR registry URL
required: true
acrUsername:
description: ACR login username
required: true
acrPassword:
description: ACR login password
required: true

runs:
using: composite
steps:
- name: Restore cached Docker image
uses: ./.github/actions/docker-image-cache-restore
with:
key: ${{ inputs.imageCacheKey }}

- name: Authenticate with ACR
id: authAcr
uses: ./.github/actions/docker-push/auth-acr
with:
acrRegistry: ${{ inputs.acrRegistry }}
acrUsername: ${{ inputs.acrUsername }}
acrPassword: ${{ inputs.acrPassword }}

- name: Push to ACR
shell: bash
run: |
docker tag ${{ inputs.sourceImage }}:${{ inputs.sourceTag }} ${{ steps.authAcr.outputs.repositoryName }}/${{ inputs.targetImage }}:${{ inputs.targetTag }}
docker push ${{ steps.authAcr.outputs.repositoryName }}/${{ inputs.targetImage }}:${{ inputs.targetTag }}
29 changes: 29 additions & 0 deletions .github/actions/docker-push/auth-acr/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Push to ACR
description: Push Docker image to ACR
inputs:
acrRegistry:
description: ACR registry URL
required: true
acrUsername:
description: ACR login username
required: true
acrPassword:
description: ACR login password
required: true
outputs:
repositoryName:
description: Repository name
value: ${{ steps.repositoryName.outputs.repository }}

runs:
using: composite
steps:
- uses: azure/docker-login@v2
with:
login-server: ${{ inputs.acrRegistry }}
username: ${{ inputs.acrUsername }}
password: ${{ inputs.acrPassword }}

- id: repositoryName
shell: bash
run: echo "repository=${{ inputs.acrRegistry }}" >> $GITHUB_OUTPUT
101 changes: 101 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
name: Build and publish
on: [ push ]

jobs:
detect-changes:
name: Detect changes
runs-on: ubuntu-latest
outputs:
changedProjects_python38: ${{ steps.findChanges.outputs.changedProjects_python38 }}
changedProjects_python310: ${{ steps.findChanges.outputs.changedProjects_python310 }}
changedProjects: ${{ steps.findChanges.outputs.changedProjects }}
steps:
- name: Checkout
uses: actions/checkout@v5
with:
fetch-depth: 0

- name: Find changes
id: findChanges
run: |
./bin/ci-find-changes.sh master \
python38:python-3.8/ \
python310:python-3.10/

build:
name: Build ${{ matrix.python-version }}
needs: detect-changes
runs-on: ubuntu-latest
strategy:
matrix:
include:
- python-version: "3.8"
target: python38
changed: ${{ needs.detect-changes.outputs.changedProjects_python38 }}
- python-version: "3.10"
target: python310
changed: ${{ needs.detect-changes.outputs.changedProjects_python310 }}
steps:
- name: Checkout
uses: actions/checkout@v5
if: matrix.changed == '1'

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
if: matrix.changed == '1'

- name: Build Docker image
if: matrix.changed == '1'
run: |
echo "Building ${{ matrix.target }}"
docker buildx build \
--tag keboola/docker-custom-python:python-${{ matrix.python-version }} \
--output type=docker,dest=/tmp/docker-custom-python-${{ matrix.target }}.tar \
./python-${{ matrix.python-version }}/

- name: Upload Docker image artifact
uses: actions/upload-artifact@v4
if: matrix.changed == '1'
with:
name: docker-custom-python-${{ matrix.target }}-${{ github.sha }}
path: /tmp/docker-custom-python-${{ matrix.target }}.tar
retention-days: 1

publish-images:
name: Publish images to ACR
if: startsWith(github.ref, 'refs/tags/')
needs: [detect-changes, build]
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout
uses: actions/checkout@v5
with:
fetch-depth: 0

- name: Push python-3.8 image to ACR
if: needs.detect-changes.outputs.changedProjects_python38 == '1'
uses: ./.github/actions/docker-push
with:
imageCacheKey: python38
sourceImage: keboola/docker-custom-python
sourceTag: python-3.8
targetImage: docker-custom-python
targetTag: python-3.8-${{ github.ref_name }}
acrRegistry: keboola.azurecr.io
acrUsername: docker-custom-python-push
acrPassword: ${{ secrets.DOCKER_CUSTOM_PYTHON_ACR_PASSWORD }}

- name: Push python-3.10 image to ACR
if: needs.detect-changes.outputs.changedProjects_python310 == '1'
uses: ./.github/actions/docker-push
with:
imageCacheKey: python310
sourceImage: keboola/docker-custom-python
sourceTag: python-3.10
targetImage: docker-custom-python
targetTag: python-3.10-${{ github.ref_name }}
acrRegistry: keboola.azurecr.io
acrUsername: docker-custom-python-push
acrPassword: ${{ secrets.DOCKER_CUSTOM_PYTHON_ACR_PASSWORD }}
104 changes: 0 additions & 104 deletions azure-pipelines.yml

This file was deleted.

14 changes: 10 additions & 4 deletions bin/ci-find-changes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ fi
TARGET_BRANCH=$1
ALL_CHANGES=

set_output() {
local var_name=$1
local value=$2
echo "${var_name}=${value}" >> "$GITHUB_OUTPUT"
}

for PROJECT in ${@:2}; do
PROJECT_CONFIG=(${PROJECT//:/ })
PROJECT_VAR_NAME=${PROJECT_CONFIG[0]}
Expand All @@ -20,10 +26,10 @@ for PROJECT in ${@:2}; do

if [[ $PROJECT_CHANGES_COUNT -eq 0 ]]; then
echo "no changes"
echo "##vso[task.setvariable variable=changedProjects_${PROJECT_VAR_NAME}]0"
set_output "changedProjects_${PROJECT_VAR_NAME}" "0"
else
echo "has changes"
echo "##vso[task.setvariable variable=changedProjects_${PROJECT_VAR_NAME}]1"
set_output "changedProjects_${PROJECT_VAR_NAME}" "1"
ALL_CHANGES="${ALL_CHANGES} \"${PROJECT_VAR_NAME}\""
fi
done
Expand All @@ -34,9 +40,9 @@ if [[ "${ALL_CHANGES}" == "" ]]; then
PROJECT_CONFIG=(${PROJECT//:/ })
PROJECT_VAR_NAME=${PROJECT_CONFIG[0]}

echo "##vso[task.setvariable variable=changedProjects_${PROJECT_VAR_NAME}]1"
set_output "changedProjects_${PROJECT_VAR_NAME}" "1"
ALL_CHANGES="${ALL_CHANGES} \"${PROJECT_VAR_NAME}\""
done
fi

echo "##vso[task.setvariable variable=changedProjects]$ALL_CHANGES"
set_output "changedProjects" "$ALL_CHANGES"
11 changes: 1 addition & 10 deletions docker-bake.hcl
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
group "default" {
targets = [
"python38",
"python310",
"pythonSnowpark"
"python310"
]
}

Expand All @@ -15,11 +14,3 @@ target "python310" {
context = "./python-3.10/"
tags = ["keboola/docker-custom-python:python-3.10"]
}

target "pythonSnowpark" {
context = "./python-snowpark/"
tags = ["keboola/docker-custom-python-snowpark"]
contexts = {
python = "target:python38"
}
}
Loading