Skip to content

Commit c76ebc0

Browse files
committed
style: formats and phrases
1 parent c9d5aec commit c76ebc0

File tree

4 files changed

+125
-5
lines changed

4 files changed

+125
-5
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: 'DC: Delete Registry Images'
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
delete_since_days:
7+
required: false
8+
type: string
9+
description: "Delete images older than the specified number of days and exit gracefully"
10+
default: ''
11+
12+
# Special permissions required for OIDC authentication
13+
permissions:
14+
id-token: write
15+
contents: read
16+
actions: read
17+
18+
env:
19+
GH_TOKEN: ${{ secrets.GH_TOKEN }}
20+
21+
jobs:
22+
dc-registry-delete:
23+
name: 'Docker Compose: Delete Registry Images'
24+
runs-on: [self-hosted, "${{ github.event_name == 'release' && 'prod' || github.event.pull_request.base.ref }}"]
25+
environment: ${{ github.event_name == 'release' && 'prod' || github.event.pull_request.base.ref }}
26+
env:
27+
ENVIRONMENT_NAME: ${{ github.event_name == 'release' && 'prod' || github.event.pull_request.base.ref }}
28+
REGISTRY_HTTPS_USERNAME: "${{ secrets.REGISTRY_HTTPS_USERNAME }}"
29+
CONTAINER_REGISTRY: "${{ vars.CONTAINER_REGISTRY }}"
30+
IMAGE_TAG: ${{ github.event_name == 'release' && github.event.release.tag_name || 'dev' }}
31+
steps:
32+
# Checkout the repository to the GitHub Actions runner
33+
- name: Checkout
34+
uses: actions/checkout@v4
35+
36+
- name: Clone cicd-deployment-scripts
37+
run: git clone https://oauth2:${{ secrets.GH_TOKEN }}@github.com/code-kern-ai/cicd-deployment-scripts.git
38+
39+
- name: Perform Registry Image Deletion
40+
run: |
41+
bash cicd-deployment-scripts/dc/registry_delete.sh \
42+
-e ${{ env.ENVIRONMENT_NAME }} \
43+
-g ${{ github.repository_owner }} \
44+
-r ${{ env.CONTAINER_REGISTRY }} \
45+
-a ${{ github.event.repository.name }} \
46+
-t ${{ github.ref_name }} \
47+
-u ${{ env.REGISTRY_HTTPS_USERNAME }} \
48+
-d ${{ inputs.delete_since_days }}

.github/workflows/pi_merge_parent_image.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ jobs:
9797
platform=linux/arm64
9898
label=dockerfile-path=https://github.com/refinery-${{ env.PARENT_IMAGE_TYPE }}-parent-image/blob/${{ github.sha }}/Dockerfile
9999
100-
- name: Build & Push ${{ env.PARENT_IMAGE_NAME }}:sha-${{ env.PARENT_IMAGE_TYPE }}
100+
- name: Build & Push ${{ env.PARENT_IMAGE_NAME }}:${{ github.sha }}-${{ env.PARENT_IMAGE_TYPE }}
101101
uses: docker/build-push-action@v5
102102
with:
103103
context: .
@@ -111,7 +111,7 @@ jobs:
111111
platform=linux/amd64
112112
label=dockerfile-path=https://github.com/refinery-${{ env.PARENT_IMAGE_TYPE }}-parent-image/blob/${{ github.sha }}/Dockerfile
113113
114-
- name: Build & Push ${{ env.PARENT_IMAGE_NAME }}:sha-${{ env.PARENT_IMAGE_TYPE }}-arm64
114+
- name: Build & Push ${{ env.PARENT_IMAGE_NAME }}:${{ github.sha }}-${{ env.PARENT_IMAGE_TYPE }}-arm64
115115
uses: docker/build-push-action@v5
116116
with:
117117
context: .

.github/workflows/pi_merge_submodule.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ jobs:
8686
needs: [pi-matrix, pi-update-submodule]
8787
if: ${{ !failure() }}
8888
runs-on: ubuntu-latest
89-
strategy:
90-
matrix:
91-
parent_image_type: ${{ fromJson(needs.pi-matrix.outputs.parent_image_type) }}
89+
# strategy:
90+
# matrix:
91+
# parent_image_type: ${{ fromJson(needs.pi-matrix.outputs.parent_image_type) }}
9292
steps:
9393
- name: Checkout repository
9494
uses: actions/checkout@v4

dc/registry_delete.sh

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# !/bin/bash
2+
set -e
3+
4+
ENVIRONMENT_NAME="dev"
5+
GITHUB_OWNER="code-kern-ai"
6+
REGISTRY_URL="registry.dev.kern.ai"
7+
APP_NAME="hosted-inference-api"
8+
DELETE_TAG=""
9+
HTTPS_USERNAME=""
10+
DELETE_SINCE_DAYS=""
11+
12+
while getopts e:g:r:a:t:u:d: flag
13+
do
14+
case "${flag}" in
15+
e) ENVIRONMENT_NAME=${OPTARG};;
16+
g) GITHUB_OWNER=${OPTARG};;
17+
r) REGISTRY_URL=${OPTARG};;
18+
a) APP_NAME=${OPTARG};;
19+
t) DELETE_TAG=${OPTARG};;
20+
u) HTTPS_USERNAME=${OPTARG};;
21+
d) DELETE_SINCE_DAYS=${OPTARG};;
22+
esac
23+
done
24+
25+
26+
# Delete images older than DELETE_SINCE_DAYS and exit 0
27+
if [ -n "$DELETE_SINCE_DAYS" ]; then
28+
echo "::notice::Deleting images older than $DELETE_SINCE_DAYS days"
29+
repo_tags=$(curl -s -u $HTTPS_USERNAME https://$REGISTRY_URL/v2/$GITHUB_OWNER/$APP_NAME/tags/list | jq -r '.tags[]')
30+
echo $repo_tags | while read -r tag ; do
31+
created=$(curl -s -u $HTTPS_USERNAME \
32+
https://$REGISTRY_URL/v2/$GITHUB_OWNER/$APP_NAME/manifests/$tag \
33+
| jq -r '.history[0].v1Compatibility' | jq -r '.created')
34+
35+
created_date=$(date -d $created +%s)
36+
current_date=$(date +%s)
37+
days_since=$(( (current_date - created_date) / (60*60*24) ))
38+
39+
if [ $days_since -gt $DELETE_SINCE_DAYS ]; then
40+
digest=$(curl -s -u $HTTPS_USERNAME \
41+
-H "Accept: application/vnd.docker.distribution.manifest.v2+json" \
42+
https://$REGISTRY_URL/v2/$GITHUB_OWNER/$APP_NAME/manifests/$tag \
43+
| sha256sum | cut -d ' ' -f 1)
44+
curl -X DELETE -u $HTTPS_USERNAME https://$REGISTRY_URL/v2/$GITHUB_OWNER/$APP_NAME/manifests/sha256:$digest
45+
echo "::warning::deleted $APP_NAME:$tag, $days_since days old"
46+
else
47+
echo "::notice::$APP_NAME:$tag is $days_since days old"
48+
fi
49+
done
50+
exit 0
51+
fi
52+
53+
# Delete a specific image and exit 0
54+
if [ -n $DELETE_TAG ]; then
55+
manifest=$(curl -s -u $HTTPS_USERNAME \
56+
-H "Accept: application/vnd.docker.distribution.manifest.v2+json" \
57+
https://$REGISTRY_URL/v2/$GITHUB_OWNER/$APP_NAME/manifests/$DELETE_TAG)
58+
59+
errors=$(echo $manifest | jq -r '.errors')
60+
if [ $errors != null ]; then
61+
echo "::error::$REGISTRY_URL/$APP_NAME:$DELETE_TAG not found"
62+
exit 1
63+
fi
64+
65+
digest=$(echo $manifest | sha256sum | cut -d ' ' -f 1)
66+
67+
curl -X DELETE -u $HTTPS_USERNAME \
68+
https://$REGISTRY_URL/v2/$GITHUB_OWNER/$APP_NAME/manifests/sha256:$digest
69+
70+
echo "::warning::deleted $REGISTRY_URL/$GITHUB_OWNER/$APP_NAME:$DELETE_TAG"
71+
exit 0
72+
fi

0 commit comments

Comments
 (0)