1- name : Build and Push Images
1+ name : Container Image Build and Push
22
33on :
4- push :
5- branches :
6- - main
7- tags :
8- - " v*"
4+ release :
5+ types : [created]
96
107permissions :
118 contents : read
129 packages : write
1310 id-token : write
1411
12+ env :
13+ REGISTRY : ghcr.io
14+ HUB_IMAGE_NAME : ${{ github.repository }}
15+ AGENT_IMAGE_NAME : ${{ github.repository }}-agent
16+
1517jobs :
16- build-hub :
18+ build-and-push- hub-image :
1719 runs-on : ubuntu-latest
20+ permissions :
21+ contents : read
22+ packages : write
1823 steps :
19- - uses : actions/checkout@v4
24+ - name : Checkout repository
25+ uses : actions/checkout@v4
26+
27+ - name : Log in to the Container registry
28+ uses : docker/login-action@v3
29+ with :
30+ registry : ${{ env.REGISTRY }}
31+ username : ${{ github.actor }}
32+ password : ${{ secrets.GITHUB_TOKEN }}
2033
2134 - name : Set up Docker Buildx
2235 uses : docker/setup-buildx-action@v3
2336
24- - name : Login to GitHub Container Registry
37+ - name : Extract metadata (tags, labels) for Docker
38+ id : meta
39+ uses : docker/metadata-action@v5
40+ with :
41+ images : ${{ env.REGISTRY }}/${{ env.HUB_IMAGE_NAME }}
42+
43+ - name : Build and push Docker image
44+ uses : docker/build-push-action@v6
45+ with :
46+ context : .
47+ file : ./deploy/Dockerfile.hub
48+ platforms : linux/amd64,linux/arm64
49+ push : true
50+ tags : ${{ steps.meta.outputs.tags }}
51+ labels : ${{ steps.meta.outputs.labels }}
52+ build-args : |
53+ VERSION=${{ github.ref_name }}
54+ GIT_COMMIT=${{ github.sha }}
55+ BUILD_DATE=${{ github.event.release.created_at }}
56+
57+ build-and-push-agent-image :
58+ runs-on : ubuntu-latest
59+ permissions :
60+ contents : read
61+ packages : write
62+ steps :
63+ - name : Checkout repository
64+ uses : actions/checkout@v4
65+
66+ - name : Log in to the Container registry
2567 uses : docker/login-action@v3
2668 with :
27- registry : ghcr.io
69+ registry : ${{ env.REGISTRY }}
2870 username : ${{ github.actor }}
2971 password : ${{ secrets.GITHUB_TOKEN }}
3072
31- - name : Install Helm
32- uses : azure/setup-helm@v3
33- with :
34- version : ' v3.12.0'
73+ - name : Set up Docker Buildx
74+ uses : docker/setup-buildx-action@v3
3575
36- - name : Extract metadata
76+ - name : Extract metadata (tags, labels) for Docker
3777 id : meta
3878 uses : docker/metadata-action@v5
3979 with :
40- images : ghcr.io/faroshq/kedge-hub
41- tags : |
42- type=semver,pattern={{version}}
43- type=semver,pattern={{major}}.{{minor}}
44- type=sha
80+ images : ${{ env.REGISTRY }}/${{ env.AGENT_IMAGE_NAME }}
4581
46- - name : Build and push
82+ - name : Build and push Docker image
4783 uses : docker/build-push-action@v6
4884 with :
4985 context : .
50- file : deploy/Dockerfile.hub
86+ file : ./deploy/Dockerfile.agent
87+ platforms : linux/amd64,linux/arm64
5188 push : true
5289 tags : ${{ steps.meta.outputs.tags }}
5390 labels : ${{ steps.meta.outputs.labels }}
5491 build-args : |
5592 VERSION=${{ github.ref_name }}
5693 GIT_COMMIT=${{ github.sha }}
57- BUILD_DATE=${{ github.event.head_commit.timestamp }}
58- cache-from : type=gha
59- cache-to : type=gha,mode=max
60- platforms : linux/amd64,linux/arm64
61-
62- - name : Package and push Helm charts as OCI
63- env :
64- HELM_EXPERIMENTAL_OCI : 1
65- run : |
66- # Login to GitHub Container Registry for Helm
67- echo "${{ github.token }}" | helm registry login ghcr.io --username ${{ github.actor }} --password-stdin
68-
69- # Set chart version - use tag name if available, otherwise use semver format
70- if [[ "${{ github.ref_type }}" == "tag" ]]; then
71- CHART_VERSION="${{ github.ref_name }}"
72- # Remove 'v' prefix if present
73- CHART_VERSION="${CHART_VERSION#v}"
74- else
75- CHART_VERSION="0.0.0-${{ github.sha }}"
76- fi
77-
78- # Package and push each chart in deploy/charts/
79- for chart_dir in deploy/charts/*/; do
80- if [ -f "${chart_dir}Chart.yaml" ]; then
81- chart_name=$(basename "$chart_dir")
82- echo "Processing chart: $chart_name"
83-
84- # Update chart version and appVersion in Chart.yaml
85- sed -i "s/^version:.*/version: ${CHART_VERSION}/" "${chart_dir}Chart.yaml"
86- sed -i "s/^appVersion:.*/appVersion: ${CHART_VERSION}/" "${chart_dir}Chart.yaml"
87-
88- # Package the chart
89- helm package "$chart_dir" --version "${CHART_VERSION}"
90-
91- # Push to GitHub Container Registry
92- helm push "${chart_name}-${CHART_VERSION}.tgz" "oci://ghcr.io/${{ github.repository_owner }}/charts"
93-
94- echo "Helm chart pushed to oci://ghcr.io/${{ github.repository_owner }}/charts/${chart_name}:${CHART_VERSION}"
95- fi
96- done
94+ BUILD_DATE=${{ github.event.release.created_at }}
0 commit comments