Skip to content

Commit

Permalink
Merge pull request #37 from unicef/release/0.1
Browse files Browse the repository at this point in the history
Release/0.1
  • Loading branch information
domdinicola authored Nov 4, 2024
2 parents 1dadbc2 + b5c4dd7 commit fb6c0b6
Show file tree
Hide file tree
Showing 171 changed files with 7,852 additions and 1,725 deletions.
72 changes: 72 additions & 0 deletions .github/actions/delete_docker/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# ref: https://docs.github.com/en/actions/creating-actions/creating-a-docker-container-action
name: 'Delete Docker Image'
description: 'Delete Docker Image from Registry'
inputs:
image:
description: 'Image name to delete'
required: true
tag:
description: 'Tag to delete'
required: true
username:
description: 'Docker Username'
required: true
password:
description: 'Docker Password'
required: true
registry:
description: 'Files to use to calculate the hash'
required: false
default: "https://hub.docker.com/v2"


outputs:
checksum: # id of output
description: 'The time we greeted you'
value: ${{ steps.calc.outputs.checksum }}

runs:
using: 'composite'
steps:
- id: calc
shell: bash
run: |
registry=${{ inputs.registry }}
name=${{ inputs.image }}
tag=${{ inputs.tag }}
echo "::notice:: 111111111 Deleting Image ${name}:${tag}"
TOKEN=$(\
curl \
--silent \
--header "Content-Type: application/json" \
--request POST \
--data '{"username": "'${{ inputs.username }}'", "password": "'${{ inputs.password }}'" }' \
${registry}/users/login/ \
| jq -r .token\
)
curl -X DELETE \
--header "Authorization: JWT ${TOKEN}" \
--header "Accept: application/json" \
${registry}/repositories/${name}/tags/${tag}
# echo "::notice:: curl $auth -sI -k \
# -H 'Accept: application/vnd.docker.distribution.manifest.v2+json' \
# https://${registry}/v2/${name}/manifests/${tag}"
#
# echo "::notice:: 111111111 $auth"
#
# digest=$(curl $auth -sI -k \
# -H "Accept: application/vnd.docker.distribution.manifest.v2+json" \
# "https://${registry}/v2/${name}/manifests/${tag}")
# echo "::notice:: 111111111 ${digest}"
#
# curl $auth -X DELETE -sI -k "https://${registry}/v2/${name}/manifests/$(
# curl $auth -sI -k \
# -H "Accept: application/vnd.docker.distribution.manifest.v2+json" \
# "https://${registry}/v2/${name}/manifests/${tag}" \
# | tr -d '\r' | sed -En 's/^Docker-Content-Digest: (.*)/\1/pi'
# )"
23 changes: 15 additions & 8 deletions .github/actions/docker_build/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ outputs:
value: ${{ steps.meta.outputs.version }}
created:
description: 'True if new image has been created'
value: ${{ !steps.image_status.outputs.updated }}
value: ${{ steps.status.outputs.created }}
digest:
description: 'Built image digest'
value: ${{ !steps.build_push.outputs.digest }}
value: ${{ steps.build_push.outputs.digest }}
imageId:
description: 'Built image ID'
value: ${{ !steps.build_push.outputs.imageId }}
value: ${{ steps.build_push.outputs.imageId }}


runs:
Expand Down Expand Up @@ -122,8 +122,10 @@ runs:
-v fatal \
${{ steps.image_name.outputs.name }} 2>/dev/null)
code_checksum="${{ inputs.code_checksum }}"
if [[ -z "$image_checksum" ]]; then
if [[ "${{ contains(github.event.head_commit.message, 'ci:all') }}" == "true" ]];then
echo "::warning::🤔 Forced rebuild"
echo "updated=false" >> $GITHUB_OUTPUT
elif [[ -z "$image_checksum" ]]; then
echo "::warning::🤔 No image checksum found"
echo "updated=false" >> $GITHUB_OUTPUT
elif [[ $image_checksum == $code_checksum ]]; then
Expand All @@ -145,7 +147,7 @@ runs:
driver-opts: |
image=moby/buildkit:v0.13.2
network=host
- name: Build and push
- name: Build and push info
if: (steps.image_status.outputs.updated != 'true' || inputs.rebuild == 'true') && inputs.dryrun == 'true'
shell: bash
run: |
Expand All @@ -164,8 +166,8 @@ runs:
with:
context: .
tags: ${{ steps.meta.outputs.tags }}
labels: "${{ steps.meta.outputs.labels }}\na=1\nb=2"
annotations: "${{ steps.meta.outputs.annotations }}\nchecksum=${{ inputs.checksum }}"
labels: "${{ steps.meta.outputs.labels }}\nchecksum=${{ inputs.code_checksum }}\ndistro=${{ inputs.target }}"
annotations: "${{ steps.meta.outputs.annotations }}\nchecksum=${{ inputs.code_checksum }}\ndistro=${{ inputs.target }}"
target: ${{ inputs.target }}
file: ./docker/Dockerfile
platforms: linux/amd64
Expand All @@ -178,11 +180,16 @@ runs:
GITHUB_SERVER_URL=${{ github.server_url }}
GITHUB_REPOSITORY=${{ github.repository }}
BUILD_DATE=${{ env.BUILD_DATE }}
DISTRO=${{ inputs.target }}
CHECKSUM=${{ inputs.code_checksum }}
VERSION=${{ steps.meta.outputs.version }}
SOURCE_COMMIT=${{ steps.last_commit.outputs.last_commit_short_sha }}
- name: Status
id: status
if: (steps.image_status.outputs.updated != 'true' || inputs.rebuild == 'true') && inputs.dryrun != 'true'
shell: bash
run: |
echo "${{ toJSON(steps.build_push.outputs) }}"
regctl image inspect -p linux/amd64 ${{ steps.image_name.outputs.name }}
echo "::notice:: Image ${{ steps.meta.outputs.tags }} successfully built and pushed"
echo "created=true" >> $GITHUB_OUTPUT
3 changes: 2 additions & 1 deletion .github/file-filters.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# This is used by the action https://github.com/dorny/paths-filter
docker: &docker
- added|modified: './docker/**'
- added|modified: './docker/**/*'
- added|modified: './docker/*'

dependencies: &dependencies
- 'pdm.lock'
Expand Down
59 changes: 25 additions & 34 deletions .github/workflows/delete_image.yml
Original file line number Diff line number Diff line change
@@ -1,39 +1,30 @@
name: Branch Deleted
name: Delete Outdated Docker Image
on: delete
jobs:
delete:
if: github.event.ref_type == 'branch'
delete_branch:
if: github.event.ref_type == 'branch' || github.event.ref_type == 'tag'
runs-on: ubuntu-latest
steps:
- name: Docker meta
id: meta
uses: docker/metadata-action@v5

- name: Delete Test Docker Image
shell: bash
run: |
name="${{vars.DOCKER_IMAGE}}:test-${{steps.meta.outputs.version}}"
registry="https://registry-1.docker.io"
curl -v -sSL -X DELETE "http://${registry}/v2/${name}/manifests/$(
curl -sSL -I \
-H "Accept: application/vnd.docker.distribution.manifest.v2+json" \
"http://${registry}/v2/${name}/manifests/$(
curl -sSL "http://${registry}/v2/${name}/tags/list" | jq -r '.tags[0]'
)" \
| awk '$1 == "Docker-Content-Digest:" { print $2 }' \
| tr -d $'\r' \
)"
- name: Delete linked Docker Image
shell: bash
- name: Checkout code
uses: actions/[email protected]
- shell: bash
run: |
name="${{vars.DOCKER_IMAGE}}:${{steps.meta.outputs.version}}"
registry="https://registry-1.docker.io"
curl -v -sSL -X DELETE "http://${registry}/v2/${name}/manifests/$(
curl -sSL -I \
-H "Accept: application/vnd.docker.distribution.manifest.v2+json" \
"http://${registry}/v2/${name}/manifests/$(
curl -sSL "http://${registry}/v2/${name}/tags/list" | jq -r '.tags[0]'
)" \
| awk '$1 == "Docker-Content-Digest:" { print $2 }' \
| tr -d $'\r' \
)"
ref="${{github.ref}}"
tag=$(echo $ref | sed -e "s#refs/heads/##g" | sed -e s#/#-##g)
echo "ref=$ref" >> $GITHUB_ENV
echo "dist_tag=$tag" >> $GITHUB_ENV
echo "test_tag=test-${tag}" >> $GITHUB_ENV
- uses: ./.github/actions/delete_docker
if: github.event.ref_type == 'tag'
with:
image: ${{vars.DOCKER_IMAGE}}
tag: ${{ env.dist_tag }}
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- uses: ./.github/actions/delete_docker
with:
image: ${{vars.DOCKER_IMAGE}}
tag: ${{ env.test_tag }}
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
21 changes: 12 additions & 9 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@ on:
push:
branches:
- develop
# - master
# - staging
# - releases/*
pull_request:
branches: [develop, master]
types: [synchronize, opened, reopened, ready_for_review]
- master
- staging
- release/*
- feature/*
- bugfix/*
- hotfix/*
# pull_request:
# branches: [develop, master]
# types: [synchronize, opened, reopened, ready_for_review]

defaults:
run:
Expand Down Expand Up @@ -49,7 +52,7 @@ jobs:
if: github.event.pull_request.draft == false && needs.changes.outputs.lint
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v2
- uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install requirements
Expand All @@ -66,7 +69,7 @@ jobs:
if: github.event.pull_request.draft == false && needs.changes.outputs.lint
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v2
- uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install requirements
Expand All @@ -79,7 +82,7 @@ jobs:
if: github.event.pull_request.draft == false && needs.changes.outputs.lint
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v2
- uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install requirements
Expand Down
Loading

0 comments on commit fb6c0b6

Please sign in to comment.