Skip to content

Commit 338c4af

Browse files
committed
Merge pull request #50 from NethermindEth/feature/app-build
feat: added acctions: docker-build-and-push-image and jfrog-build-pub…
2 parents 85752c0 + 1737e3e commit 338c4af

File tree

3 files changed

+213
-0
lines changed

3 files changed

+213
-0
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
name: 'Build Docker Image'
2+
description: ''
3+
4+
inputs:
5+
registry_username:
6+
description: 'Username for Artifactory'
7+
required: true
8+
registry_password:
9+
description: 'Password for Artifactory'
10+
required: true
11+
image_reportory:
12+
description: 'Repository name'
13+
required: true
14+
image_name:
15+
description: 'Name of the image'
16+
required: true
17+
image_tag:
18+
description: 'Tag of the image'
19+
required: true
20+
platforms:
21+
description: 'Comma-separated list of platforms (e.g., linux/amd64,linux/arm64)'
22+
required: true
23+
cache_from:
24+
description: 'List of external cache sources (e.g., type=local,src=path/to/dir)'
25+
default: type=gha
26+
required: false
27+
cache_to:
28+
description: 'List of cache export destinations (e.g., type=local,dest=path/to/dir)'
29+
default: type=gha,mode=max
30+
required: false
31+
add_tag_latest:
32+
description: 'Additionally push with latest tag'
33+
required: false
34+
default: 'false'
35+
36+
runs:
37+
using: "composite"
38+
steps:
39+
- name: Login to Docker Hub
40+
uses: docker/login-action@v3
41+
with:
42+
registry: ${{ vars.JFROG_HOST }}/${{ inputs.image_reportory }}
43+
username: ${{ secrets.ARTIFACTORY_ANGKOR_USERNAME }}
44+
password: ${{ secrets.ARTIFACTORY_ANGKOR_TOKEN_DEVELOPER }}
45+
46+
- name: Set up QEMU
47+
uses: docker/setup-qemu-action@v3
48+
49+
- name: Set up Docker Buildx
50+
uses: docker/setup-buildx-action@v3
51+
52+
- name: Generate image tags
53+
shell: bash
54+
run: |
55+
BUILD_TAGS="${{ vars.JFROG_HOST }}/${{ inputs.image_reportory }}/${{ inputs.image_name }}:${{ inputs.image_tag }}"
56+
if [[ "${{ inputs.add_tag_latest }}" == "true" ]]; then
57+
BUILD_TAGS="${BUILD_TAGS}\n${{ vars.JFROG_HOST }}/${{ inputs.image_reportory }}/${{ inputs.image_name }}:latest"
58+
fi
59+
echo "BUILD_TAGS=${BUILD_TAGS}" >> $GITHUB_ENV
60+
61+
- name: Build and push
62+
id: build
63+
uses: docker/build-push-action@v6
64+
with:
65+
push: true
66+
platforms: ${{ inputs.platforms }}
67+
tags: ${{ env.BUILD_TAGS }}
68+
cache-from: type=gha
69+
cache-to: type=gha,mode=max
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
name: 'Publish build-info to JFrog'
2+
description: 'Collects information about the build and publishes it to JFrog'
3+
4+
inputs:
5+
jfrog_project:
6+
description: 'Key of the JFrog project'
7+
required: true
8+
image_reportory:
9+
description: 'Repository name'
10+
required: true
11+
image_name:
12+
description: 'Name of the image'
13+
required: true
14+
image_tag:
15+
description: 'Tag of the image'
16+
required: true
17+
platforms:
18+
description: 'Comma-separated list of platforms (e.g., linux/amd64,linux/arm64)'
19+
required: true
20+
21+
runs:
22+
using: composite
23+
steps:
24+
- name: Install JFrog CLI
25+
uses: jfrog/setup-jfrog-cli@v4
26+
env:
27+
JF_URL: ${{ vars.JFROG_URL }}
28+
JF_PROJECT: ${{ inputs.jfrog_project }}
29+
with:
30+
oidc-provider-name: github-nethermindeth
31+
32+
- name: JFrog build add context
33+
env:
34+
JFROG_CLI_BUILD_NAME: ${{ inputs.image_name }}
35+
JFROG_CLI_BUILD_NUMBER: ${{ inputs.image_tag }}-${{ github.run_number }}
36+
shell: bash
37+
run: |
38+
jf rt build-collect-env
39+
jf rt build-add-git
40+
41+
- name: JFrog build add images
42+
env:
43+
JFROG_CLI_BUILD_NAME: ${{ inputs.image_name }}
44+
JFROG_CLI_BUILD_NUMBER: ${{ inputs.image_tag }}-${{ github.run_number }}
45+
shell: bash
46+
run: |
47+
# Pull image manifest
48+
docker manifest inspect ${{ vars.JFROG_HOST }}/${{ inputs.image_reportory }}/${{ inputs.image_name }}:${{ inputs.image_tag }} > manifest.json
49+
50+
# Iterate over platforms
51+
platforms=$(echo ${{ inputs.platforms }} | tr ',' ' ')
52+
for platform in $platforms; do
53+
os=$(echo $platform | cut -d'/' -f1)
54+
arch=$(echo $platform | cut -d'/' -f2)
55+
digest=$(jq -r \
56+
--arg os "${os}" \
57+
--arg arch "${arch}" \
58+
'.manifests[] | select(.platform.os==$os and .platform.architecture==$arch) | .digest' manifest.json)
59+
echo "${{ vars.JFROG_HOST }}/${{ inputs.image_reportory }}/${{ inputs.image_name }}:${{ inputs.image_tag }}@${digest}" > image-file
60+
jf rt build-docker-create --image-file=image-file ${{ inputs.image_reportory }}
61+
done
62+
63+
- name: JFrog build publish
64+
env:
65+
JFROG_CLI_BUILD_NAME: ${{ inputs.image_name }}
66+
JFROG_CLI_BUILD_NUMBER: ${{ inputs.image_tag }}-${{ github.run_number }}
67+
shell: bash
68+
run: |
69+
jf rt build-publish
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
name: CI pull request
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
jfrog_project:
7+
description: 'Key of the JFrog project'
8+
type: string
9+
required: true
10+
image_reportory:
11+
description: 'Repository name'
12+
type: string
13+
required: true
14+
platforms:
15+
description: 'Comma-separated list of platforms (e.g., linux/amd64,linux/arm64)'
16+
type: string
17+
required: true
18+
19+
secrets:
20+
registry_username:
21+
description: 'Username for Artifactory'
22+
required: true
23+
registry_password:
24+
description: 'Password for Artifactory'
25+
required: true
26+
27+
permissions:
28+
id-token: write
29+
contents: read
30+
31+
jobs:
32+
pipeline:
33+
runs-on: ubuntu-latest
34+
steps:
35+
# - name: Checkout
36+
# uses: actions/checkout@v4
37+
# with:
38+
# fetch-depth: 0
39+
# ref: ${{ github.head_ref }}
40+
#
41+
# - name: Run pre-commit
42+
# uses: pre-commit/action@v3.0.1
43+
44+
- name: Define image tag
45+
id: set_tag
46+
run: |
47+
GITHUB_REPOSITORY=${{ github.repository }}
48+
IMAGE_NAME=${GITHUB_REPOSITORY#*/}
49+
HEAD_REF=${{ github.head_ref }}
50+
HEAD_SLUG=${HEAD_REF//\//-}
51+
SHORT_SHA=$(git rev-parse --short HEAD)
52+
IMAGE_TAG=${HEAD_SLUG}-${{ github.sha }}
53+
echo "HEAD_SLUG=${HEAD_SLUG}" >> $GITHUB_ENV
54+
echo "IMAGE_NAME=${IMAGE_NAME}" >> $GITHUB_ENV
55+
echo "IMAGE_TAG=${IMAGE_TAG}" >> $GITHUB_ENV
56+
57+
- name: Build and push image
58+
uses: ./.github/actions/docker-build-and-push
59+
with:
60+
registry_username: ${{ secrets.registry_username }}
61+
registry_password: ${{ secrets.registry_password }}
62+
image_reportory: ${{ inputs.image_reportory }}
63+
image_name: ${{ env.IMAGE_NAME }}
64+
image_tag: ${{ env.IMAGE_TAG }}
65+
platforms: ${{ inputs.platforms }}
66+
add_tag_latest: true
67+
68+
- name: Publish Build Info to JFrog
69+
uses: ./.github/actions/jfrog-build-publish
70+
with:
71+
jfrog_project: ${{ inputs.jfrog_project }}
72+
image_reportory: ${{ inputs.image_reportory }}
73+
image_name: ${{ env.IMAGE_NAME }}
74+
image_tag: ${{ env.IMAGE_TAG }}
75+
platforms: ${{ inputs.platforms }}

0 commit comments

Comments
 (0)