Skip to content

Parent images CI/CD #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 63 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
1f368ab
feat: add parent images build
andhreljaKern Dec 4, 2024
08dc28c
test: cicd-deployment-scripts checkout parent-images
andhreljaKern Dec 4, 2024
cee4878
test: git clone from parent-images
andhreljaKern Dec 4, 2024
a1a8a61
perf: add diff ref param to build
andhreljaKern Dec 4, 2024
66853ec
debug: add print statements
andhreljaKern Dec 4, 2024
84a3e10
perf: update checkout config
andhreljaKern Dec 4, 2024
551fe23
perf: update build
andhreljaKern Dec 4, 2024
7cdd8cd
perf: install pip dependencies
andhreljaKern Dec 4, 2024
ec86e8e
feat: add pi docker build
andhreljaKern Dec 4, 2024
78a9c9f
chore: rename build to compile
andhreljaKern Dec 4, 2024
2d6edc6
fix: use environment secrets instead of repo
andhreljaKern Dec 5, 2024
3dd4dbe
fix: docker build context
andhreljaKern Dec 5, 2024
938804e
test: upload requirments artifacts
andhreljaKern Dec 5, 2024
69f83a9
test: skip docker builds to speed up execution
andhreljaKern Dec 5, 2024
54a3eb8
fix: update pi-build needs
andhreljaKern Dec 5, 2024
7b70c97
fix: upload artifacts settings
andhreljaKern Dec 5, 2024
5362d09
test: update submodules
andhreljaKern Dec 5, 2024
796c0fb
fix: purge downloadable artifact
andhreljaKern Dec 5, 2024
fdcdece
fix: purge downloadable artifact
andhreljaKern Dec 5, 2024
9d4e5f0
test: checkout submodules
andhreljaKern Dec 5, 2024
b62abde
test: checkout submodules
andhreljaKern Dec 5, 2024
818f996
test: checkout submodules
andhreljaKern Dec 5, 2024
385d07a
test: checkout submodules
andhreljaKern Dec 5, 2024
d8d8be3
test: checkout submodules
andhreljaKern Dec 5, 2024
0e8eab9
test: checkout submodules
andhreljaKern Dec 5, 2024
6d0ad74
test: checkout submodules
andhreljaKern Dec 5, 2024
6f3a1c1
test: checkout submodules
andhreljaKern Dec 5, 2024
276d7d4
perf: compile artifacts & update child repo
andhreljaKern Dec 5, 2024
7d5bf95
fix: add git config
andhreljaKern Dec 5, 2024
53718ef
perf: update git config
andhreljaKern Dec 5, 2024
b122469
test: update git config
andhreljaKern Dec 5, 2024
88bc8e9
test: update permission scope
andhreljaKern Dec 5, 2024
c4badbe
test: update permission scope
andhreljaKern Dec 5, 2024
765a3aa
test: git push
andhreljaKern Dec 5, 2024
bc64d92
test: git push
andhreljaKern Dec 5, 2024
81840cc
test: git push
andhreljaKern Dec 5, 2024
e78533b
test: git push
andhreljaKern Dec 5, 2024
a805760
perf: separate build from smodules merge
andhreljaKern Dec 5, 2024
4e466b0
perf: add strategy includes
andhreljaKern Dec 5, 2024
15164fe
test: matrix executions
andhreljaKern Dec 5, 2024
e7a1810
test: matrix executions
andhreljaKern Dec 5, 2024
26a5b44
test: matrix executions
andhreljaKern Dec 5, 2024
45d598b
test: matrix executions
andhreljaKern Dec 5, 2024
577a7e6
test: matrix executions
andhreljaKern Dec 5, 2024
642a99c
perf: add settings.sh
andhreljaKern Dec 5, 2024
1c2f8d9
fix: outputting matrix
andhreljaKern Dec 5, 2024
f0eee7e
fix: outputting matrix
andhreljaKern Dec 5, 2024
502e7de
fix: outputting matrix
andhreljaKern Dec 5, 2024
ec5f830
fix: outputting matrix
andhreljaKern Dec 5, 2024
72063ac
fix: outputting matrix
andhreljaKern Dec 5, 2024
2adb230
perf: create PR for app requirements
andhreljaKern Dec 5, 2024
205d0a1
fix: pip-compile path
andhreljaKern Dec 5, 2024
844731f
fix: pi build order of operations
andhreljaKern Dec 5, 2024
b61ae1c
style: rename jobs and steps
andhreljaKern Dec 5, 2024
a71c996
feat: rename diff.sh
andhreljaKern Dec 5, 2024
634331e
perf: requirements compilation
andhreljaKern Dec 5, 2024
3a2ac3f
test: log outputs
andhreljaKern Dec 5, 2024
994c221
chore: continue-on-error
andhreljaKern Dec 5, 2024
b7006b6
chore: quiet pip-compile
andhreljaKern Dec 5, 2024
51a26ee
feat: make pi-matrix reusable
andhreljaKern Dec 6, 2024
8307ba7
feat: add merge, release workflows
andhreljaKern Dec 6, 2024
458a1c7
fix: pr number input param for pi-matrix
andhreljaKern Dec 6, 2024
9e194ff
perf: include repository input
andhreljaKern Dec 6, 2024
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
130 changes: 130 additions & 0 deletions .github/workflows/pi_build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
name: 'Parent Images: Build'

on:
workflow_call:

# Special permissions required for OIDC authentication
permissions:
id-token: write
contents: read
actions: read

env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}

jobs:
pi-matrix:
uses: code-kern-ai/cicd-deployment-scripts/.github/workflows/pi_matrix.yml@parent-images
secrets: inherit
with:
repository: "${{ github.repository_owner }}/refinery-submodule-parent-images"

pi-build:
name: 'Parent Images: Docker Build'
runs-on: ubuntu-latest
needs: [pi-matrix]
environment: dev
env:
PYTHON_VERSION: ${{ vars.PYTHON_VERSION }}
DEV_CONTAINER_REGISTRY: ${{ vars.DEV_CONTAINER_REGISTRY }}
DEV_LOGIN_USERNAME: ${{ secrets.DEV_LOGIN_USERNAME }}
DEV_LOGIN_PASSWORD: ${{ secrets.DEV_LOGIN_PASSWORD }}
IMAGE_TAG: ${{ github.event_name == 'release' && github.event.release.tag_name || github.event.pull_request.head.ref }}
strategy:
matrix:
parent_image_type: ${{ fromJson(needs.pi-matrix.outputs.parent_image_type) }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
token: ${{ secrets.GH_TOKEN }}
repository: '${{ github.repository_owner }}/refinery-${{ matrix.parent_image_type }}-parent-image'
fetch-depth: 0
submodules: 'true'

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}

- name: Install Dependencies
run: python -m pip install pip-tools

- name: Compile Requirements
run: |
cd ${{ github.workspace }}/submodules/parent-images
git checkout ${{ github.event.pull_request.head.ref }}
pip-compile requirements/${{ matrix.parent_image_type }}-requirements.in

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
platforms: linux/amd64,linux/arm64

- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: arm64,arm

- name: Log into DEV registry
uses: docker/login-action@v3
with:
registry: "${{ env.DEV_CONTAINER_REGISTRY }}"
username: "${{ env.DEV_LOGIN_USERNAME }}"
password: "${{ env.DEV_LOGIN_PASSWORD }}"

- name: Build & Push refinery-parent-images:${{ github.event.pull_request.head.ref }}-${{ matrix.parent_image_type }}
uses: docker/build-push-action@v5
with:
context: .
cache-from: type=registry,ref=${{ env.DEV_CONTAINER_REGISTRY }}/refinery-parent-images:${{ github.event.pull_request.head.ref }}-${{ matrix.parent_image_type }}-cache
cache-to: type=registry,ref=${{ env.DEV_CONTAINER_REGISTRY }}/refinery-parent-images:${{ github.event.pull_request.head.ref }}-${{ matrix.parent_image_type }}-cache,mode=max,image-manifest=true
platforms: linux/amd64
file: Dockerfile
tags: ${{ env.DEV_CONTAINER_REGISTRY }}/refinery-parent-images:${{ github.event.pull_request.head.ref }}-${{ matrix.parent_image_type }}
push: true
build-args: |
platform=linux/amd64
label=dockerfile-path=https://github.com/refinery-${{ matrix.parent_image_type }}-parent-image/blob/${{ github.sha }}/Dockerfile

- name: Build & Push refinery-parent-images:${{ github.event.pull_request.head.ref }}-${{ matrix.parent_image_type }}-arm64
uses: docker/build-push-action@v5
with:
context: .
cache-from: type=registry,ref=${{ env.DEV_CONTAINER_REGISTRY }}/refinery-parent-images:${{ github.event.pull_request.head.ref }}-${{ matrix.parent_image_type }}-arm64-cache
cache-to: type=registry,ref=${{ env.DEV_CONTAINER_REGISTRY }}/refinery-parent-images:${{ github.event.pull_request.head.ref }}-${{ matrix.parent_image_type }}-arm64-cache,mode=max,image-manifest=true
platforms: linux/arm64
file: Dockerfile
tags: ${{ env.DEV_CONTAINER_REGISTRY }}/refinery-parent-images:${{ github.event.pull_request.head.ref }}-${{ matrix.parent_image_type }}-arm64
push: true
build-args: |
platform=linux/arm64
label=dockerfile-path=https://github.com/refinery-${{ matrix.parent_image_type }}-parent-image/blob/${{ github.sha }}/Dockerfile

- name: Build & Push refinery-parent-images:sha-${{ matrix.parent_image_type }}
uses: docker/build-push-action@v5
with:
context: .
cache-from: type=registry,ref=${{ env.DEV_CONTAINER_REGISTRY }}/refinery-parent-images:${{ github.sha }}-${{ matrix.parent_image_type }}-cache
cache-to: type=registry,ref=${{ env.DEV_CONTAINER_REGISTRY }}/refinery-parent-images:${{ github.sha }}-${{ matrix.parent_image_type }}-cache,mode=max,image-manifest=true
platforms: linux/amd64
file: Dockerfile
tags: ${{ env.DEV_CONTAINER_REGISTRY }}/refinery-parent-images:${{ github.sha }}-${{ matrix.parent_image_type }}
push: true
build-args: |
platform=linux/amd64
label=dockerfile-path=https://github.com/refinery-${{ matrix.parent_image_type }}-parent-image/blob/${{ github.sha }}/Dockerfile

- name: Build & Push refinery-parent-images:sha-${{ matrix.parent_image_type }}-arm64
uses: docker/build-push-action@v5
with:
context: .
cache-from: type=registry,ref=${{ env.DEV_CONTAINER_REGISTRY }}/refinery-parent-images:${{ github.sha }}-${{ matrix.parent_image_type }}-arm64-cache
cache-to: type=registry,ref=${{ env.DEV_CONTAINER_REGISTRY }}/refinery-parent-images:${{ github.sha }}-${{ matrix.parent_image_type }}-arm64-cache,mode=max,image-manifest=true
platforms: linux/arm64
file: Dockerfile
tags: ${{ env.DEV_CONTAINER_REGISTRY }}/refinery-parent-images:${{ github.sha }}-${{ matrix.parent_image_type }}-arm64
push: true
build-args: |
platform=linux/arm64
label=dockerfile-path=https://github.com/refinery-${{ matrix.parent_image_type }}-parent-image/blob/${{ github.sha }}/Dockerfile
50 changes: 50 additions & 0 deletions .github/workflows/pi_matrix.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: 'Parent Images: Matrix'

on:
workflow_call:
inputs:
repository:
description: 'Repository for actions/checkout'
required: false
type: string
default: ${{ github.repository }}
parent_image_type:
description: 'If specified, "include" only outputs apps associated to this parent image type'
required: false
type: string
default: ''
outputs:
parent_image_type:
description: 'List[str] of parent image types'
value: ${{ jobs.pi-matrix.outputs.parent_image_type }}
include:
description: 'List[Dict] of apps associated to parent image types'
value: ${{ jobs.pi-matrix.outputs.include }}

jobs:
pi-matrix:
name: 'Parent Images: Generate Matrix'
runs-on: ubuntu-latest
environment: dev
env:
PYTHON_VERSION: ${{ vars.PYTHON_VERSION }}
outputs:
parent_image_type: ${{ steps.generate-matrix.outputs.parent_image_type }}
include: ${{ steps.generate-matrix.outputs.include }}
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
repository: ${{ inputs.repository }}/refinery-submodule-parent-images
ref: ${{ github.event.pull_request.head.ref || github.event.repository.default_branch }}

- name: Clone cicd-deployment-scripts
run: git clone --branch parent-images https://oauth2:${{ secrets.GH_TOKEN }}@github.com/code-kern-ai/cicd-deployment-scripts.git

- name: Generate Matrix
id: generate-matrix
run: |
bash cicd-deployment-scripts/pi/matrix.sh \
-p "${{ github.event.pull_request.number || '' }}" \
-s cicd-deployment-scripts/pi/settings.sh \
-t "${{ inputs.parent_image_type }}"
133 changes: 133 additions & 0 deletions .github/workflows/pi_merge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
name: 'Parent Images: Submodules Merge'

on:
workflow_call:

# Special permissions required for OIDC authentication
permissions:
id-token: write
contents: read
actions: read

env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}

jobs:
pi-matrix:
uses: code-kern-ai/cicd-deployment-scripts/.github/workflows/pi_matrix.yml@parent-images
secrets: inherit
with:
repository: "${{ github.repository_owner }}/refinery-submodule-parent-images"

pi-update-submodule:
name: 'Parent Images: Submodules'
runs-on: ubuntu-latest
needs: [pi-matrix]
environment: dev
env:
PYTHON_VERSION: ${{ vars.PYTHON_VERSION }}
strategy:
matrix:
parent_image_type: ${{ fromJson(needs.pi-matrix.outputs.parent_image_type) }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
token: ${{ secrets.GH_TOKEN }}
repository: '${{ github.repository_owner }}/refinery-${{ matrix.parent_image_type }}-parent-image'
fetch-depth: 0
submodules: 'true'

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}

- name: Install Dependencies
run: python -m pip install pip-tools

- name: Perform Edit/Git Operations
run: |
cd ${{ github.workspace }}/submodules/parent-images
git checkout ${{ github.event.pull_request.base.ref }}

cd ${{ github.workspace }}
git checkout ${{ github.event.pull_request.head.ref }} || git checkout -b ${{ github.event.pull_request.head.ref }}
git push origin ${{ github.event.pull_request.head.ref }} && git pull origin ${{ github.event.pull_request.head.ref }}

git config user.email "devtools@kern.ai"
git config user.name "GitHub Actions"

git add submodules
git commit -m "ci: update submodules to origin/${{ github.event.pull_request.head.ref }}" || true
git push origin ${{ github.event.pull_request.head.ref }}
echo "::notice::${{ github.event.repository.name }} updated to origin/${{ github.event.pull_request.head.ref }}"

gh pr create --draft \
--title "${{ github.event.pull_request.title }}" \
--body "${{ github.event.pull_request.body }}" \
--base dev \
--head ${{ github.event.pull_request.head.ref }} \
--repo ${{ github.repository_owner }}/refinery-${{ matrix.parent_image_type }}-parent-image

pi-update-app:
name: 'Parent Images: ' # suffix populated by matrix
runs-on: ubuntu-latest
needs: [pi-matrix]
environment: dev
continue-on-error: true
env:
PYTHON_VERSION: ${{ vars.PYTHON_VERSION }}
strategy:
matrix:
include: ${{ fromJson(needs.pi-matrix.outputs.include) }}
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
repository: '${{ github.repository_owner }}/refinery-${{ matrix.parent_image_type }}-parent-image'
submodules: 'true'

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}

- name: Install Dependencies
run: python -m pip install pip-tools

- name: Clone ${{ matrix.app }}
run: git clone https://oauth2:${{ secrets.GH_TOKEN }}@github.com/${{ github.repository_owner }}/${{ matrix.app }}.git

- name: Compile Requirements
run: |
pip-compile --quiet \
--output-file ${{ matrix.app }}/requirements/${{ matrix.parent_image_type }}-requirements.txt \
submodules/parent-images/requirements/${{ matrix.parent_image_type }}-requirements.in

pip-compile --quiet \
--output-file ${{ matrix.app }}/requirements.txt \
${{ matrix.app }}/requirements/requirements.in

- name: Perform Edit/Git Operations
run: |
cd ${{ matrix.app }}

git config user.email "devtools@kern.ai"
git config user.name "GitHub Actions"

git checkout -b ${{ github.event.pull_request.head.ref }} || git checkout ${{ github.event.pull_request.head.ref }}
git push origin ${{ github.event.pull_request.head.ref }} && git pull origin ${{ github.event.pull_request.head.ref }}

git add requirements*
git commit -m "ci: update ${{ matrix.parent_image_type }}-requirements.txt"
git push origin ${{ github.event.pull_request.head.ref }}
echo "::notice::${{ matrix.app }} updated to origin/${{ github.event.pull_request.head.ref }}"

gh pr create --draft \
--title "${{ github.event.pull_request.title }}" \
--body "${{ github.event.pull_request.body }}" \
--base dev \
--head ${{ github.event.pull_request.head.ref }} \
--repo ${{ github.repository_owner }}/${{ matrix.app }}

81 changes: 81 additions & 0 deletions .github/workflows/pi_release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: 'Parent Images: Release'

on:
workflow_call:

# Special permissions required for OIDC authentication
permissions:
id-token: write
contents: read
actions: read

env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}

jobs:
pi-matrix:
uses: code-kern-ai/cicd-deployment-scripts/.github/workflows/pi_matrix.yml@parent-images
secrets: inherit
with:
repository: ${{ github.repository }}
parent_image_type: ${{ vars.PARENT_IMAGE_TYPE }}

pi-edit:
name: 'Parent Images: Dockerfile ' # suffix populated by matrix
runs-on: ubuntu-latest
needs: [pi-matrix]
environment: dev
env:
PYTHON_VERSION: ${{ vars.PYTHON_VERSION }}
DOCKERHUB_CONTAINER_REGISTRY: ${{ vars.DOCKERHUB_CONTAINER_REGISTRY }}
DOCKERHUB_LOGIN_USERNAME: ${{ secrets.DOCKERHUB_LOGIN_USERNAME }}
DOCKERHUB_LOGIN_PASSWORD: ${{ secrets.DOCKERHUB_LOGIN_PASSWORD }}
PARENT_IMAGE_NAME: ${{ vars.PARENT_IMAGE_NAME }}
PARENT_IMAGE_TYPE: ${{ vars.PARENT_IMAGE_TYPE }}
DOCKERFILE: ${{ vars.DOCKERFILE }}
strategy:
matrix:
include: ${{ fromJson(needs.pi-matrix.outputs.include) }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
token: ${{ secrets.GH_TOKEN }}
repository: ${{ github.repository_owner }}/${{ matrix.app }}

- name: Clone cicd-deployment-scripts
run: git clone --branch parent-images https://oauth2:${{ secrets.GH_TOKEN }}@github.com/code-kern-ai/cicd-deployment-scripts.git

- name: Perform Edit/Git Operations
run: |
bash cicd-deployment-scripts/pi/edit_dockerfile.sh \
-i ${{ env.PARENT_IMAGE_NAME }} \
-t ${{ matrix.parent_image_type }} \
-l ${{ github.event.release.tag_name }} \
-r ${{ env.DOCKERHUB_CONTAINER_REGISTRY }} \
-d ${{ env.DOCKERFILE }}

LATEST_IMAGE_TAG="${{ env.DOCKERHUB_CONTAINER_REGISTRY }}/${{ matrix.parent_image_type }}:${{ github.event.release.tag_name }}"
BASE_REF="dev"
HEAD_REF="parent-images"
PR_TITLE="ci(pi): update to $LATEST_IMAGE_TAG"

git config user.email "devtools@kern.ai"
git config user.name "GitHub Actions"

git checkout -b parent-images || git checkout parent-images
git push origin parent-images && git pull origin parent-images

git add ${{ env.DOCKERFILE }}
git commit -m "$PR_TITLE" || true
git push origin parent-images
echo "::notice::${{ matrix.app }} updated to $LATEST_IMAGE_TAG"

bash cicd-deployment-scripts/pi/pr_create.sh \
-b "$BASE_REF" \
-h "$HEAD_REF" \
-t "ci(pi): update to $LATEST_IMAGE_TAG" \
-o ${{ github.repository_owner }} \}}
-r ${{ github.event.repository.name }} \}}
-n ${{ github.event.release.tag_name }} \}}
-a ${{ matrix.app }}
Loading