Repository navigation
77 lines (67 loc) · 2.98 KB
/
Copy pathbuild_push.yml
File metadata and controls
77 lines (67 loc) · 2.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
name: Build_Push
on:
push:
branches:
- main
permissions:
contents: read
packages: write
jobs:
docker_build_test:
runs-on: ubuntu-24.04
name: Docker_build and Helm_build
steps:
- uses: actions/checkout@v5
- name: Build the Docker image
run: |
docker build -t ghcr.io/gabrielpalmar/hivebox:$(cat version.txt) .
docker tag ghcr.io/gabrielpalmar/hivebox:$(cat version.txt) ghcr.io/gabrielpalmar/hivebox:latest
- name: Push Docker image to GHCR
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo "$GITHUB_TOKEN" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
docker push ghcr.io/gabrielpalmar/hivebox:$(cat version.txt)
docker push ghcr.io/gabrielpalmar/hivebox:latest
# Get the SHA256 digest
DIGEST=$(docker inspect --format='{{index .RepoDigests 0}}' ghcr.io/gabrielpalmar/hivebox:$(cat version.txt) | cut -d'@' -f2)
if [ -z "$DIGEST" ]; then
echo "Failed to capture Docker digest"
exit 1
fi
echo "Image digest: $DIGEST"
echo "DOCKER_DIGEST=$DIGEST" >> $GITHUB_ENV
- name: Install Helm
run: |
curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3
chmod 700 get_helm.sh
./get_helm.sh
if ! command -v helm version &> /dev/null; then
echo "Helm could not be installed"
exit 1
fi
- name: Build Helm Chart
run: |
VERSION=$(cat version.txt)
sed -i "s/^version:.*/version: $VERSION/" ./helm-chart/Chart.yaml
sed -i "s/^appVersion:.*/appVersion: \"$VERSION\"/" ./helm-chart/Chart.yaml
sed -i "s|hivebox: ghcr.io/gabrielpalmar/hivebox:.*|hivebox: ghcr.io/gabrielpalmar/hivebox:$VERSION@$DOCKER_DIGEST|" ./helm-chart/values.yaml
helm package ./helm-chart
- name: Push Helm Chart to GHCR
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
CHART_FILE="hivebox-$(cat version.txt).tgz"
if [ ! -f "$CHART_FILE" ]; then
echo "Helm chart $CHART_FILE not found"
exit 1
fi
echo "$GITHUB_TOKEN" | helm registry login ghcr.io -u ${{ github.actor }} --password-stdin
helm push $CHART_FILE oci://ghcr.io/gabrielpalmar/hivebox-helm-charts
- name: Add job summary
run: |
VERSION=$(cat version.txt)
echo "## Build Summary" >> $GITHUB_STEP_SUMMARY
echo "- Docker image: ghcr.io/gabrielpalmar/hivebox:$VERSION" >> $GITHUB_STEP_SUMMARY
echo "- Image digest: $DOCKER_DIGEST" >> $GITHUB_STEP_SUMMARY
echo "- Helm chart: hivebox-$VERSION" >> $GITHUB_STEP_SUMMARY