11name : Deep server 🤓 GH Action 🚧
22
33on :
4+ workflow_call :
5+ inputs :
6+ push_docker_image :
7+ type : string # true or false
8+ default : " false"
9+ outputs :
10+ docker_image_name :
11+ description : " Only docker image name"
12+ value : ${{ jobs.build_test.outputs.docker_image_name }}
13+ docker_image_tag :
14+ description : " Only docker image tag"
15+ value : ${{ jobs.build_test.outputs.docker_image_tag }}
16+ docker_image :
17+ description : " docker image with tag"
18+ value : ${{ jobs.build_test.outputs.docker_image }}
419 pull_request :
5- push :
6- branches :
7- - develop
20+ # NOTE: For other, they should be run through helm github action ./helm-publish.yml
21+
822
923jobs :
1024 build_test :
1125 name : 🚴 Build + Test 🚴 # Match the name below (8398a7/action-slack).
1226 runs-on : ubuntu-latest
27+
28+ outputs :
29+ docker_image_name : ${{ steps.prep.outputs.tagged_image_name }}
30+ docker_image_tag : ${{ steps.prep.outputs.tag }}
31+ docker_image : ${{ steps.prep.outputs.tagged_image }}
32+
1333 steps :
1434 - uses : actions/checkout@master
1535
36+ - name : Login to GitHub Container Registry
37+ uses : docker/login-action@v3
38+ if : ${{ inputs.push_docker_image }}
39+ with :
40+ registry : ghcr.io
41+ username : ${{ github.actor }}
42+ password : ${{ secrets.GITHUB_TOKEN }}
43+
1644 - name : 🐳 Prepare Docker
1745 id : prep
46+ env :
47+ IMAGE_NAME : ghcr.io/${{ github.repository }}
1848 run : |
19- TAG=$(echo $GITHUB_SHA | head -c7)
20- IMAGE="docker.pkg.github.com/the-deep/server"
21- echo "tagged_image=${IMAGE}:${TAG}" >> $GITHUB_OUTPUT
49+ BRANCH_NAME=$(echo $GITHUB_REF_NAME | sed 's|:|-|' | tr '[:upper:]' '[:lower:]' | sed 's/_/-/g' | cut -c1-100 | sed 's/-*$//')
50+
51+ # XXX: Check if there is a slash in the BRANCH_NAME eg: project/add-docker
52+ if [[ "$BRANCH_NAME" == *"/"* ]]; then
53+ # XXX: Change the docker image package to -alpha
54+ IMAGE_NAME="$IMAGE_NAME-alpha"
55+ TAG="$(echo "$BRANCH_NAME" | sed 's|/|-|g').$(echo $GITHUB_SHA | head -c7)"
56+ else
57+ TAG="$BRANCH_NAME.$(echo $GITHUB_SHA | head -c7)"
58+ fi
59+
60+ IMAGE_NAME=$(echo $IMAGE_NAME | tr '[:upper:]' '[:lower:]')
61+ echo "tagged_image_name=${IMAGE_NAME}" >> $GITHUB_OUTPUT
2262 echo "tag=${TAG}" >> $GITHUB_OUTPUT
63+ echo "tagged_image=${IMAGE_NAME}:${TAG}" >> $GITHUB_OUTPUT
64+ echo "::notice::Tagged docker image: ${IMAGE_NAME}:${TAG}"
65+
2366 - name : 🐳 Set up Docker Buildx
2467 id : buildx
25- uses : docker/setup-buildx-action@master
68+ uses : docker/setup-buildx-action@v3
69+
70+ - name : 🐳 Cache Docker layers
71+ uses : actions/cache@v4
72+ with :
73+ path : /tmp/.buildx-cache
74+ key : ${{ runner.os }}-buildx-${{ github.ref }}
75+ restore-keys : |
76+ ${{ runner.os }}-buildx-refs/develop
77+ ${{ runner.os }}-buildx-
2678
2779 - name : 🐳 Build image
28- uses : docker/build-push-action@v4
80+ uses : docker/build-push-action@v6
2981 with :
3082 context : .
3183 builder : ${{ steps.buildx.outputs.name }}
3284 file : Dockerfile
3385 push : false # This would be set to true in a real world deployment scenario.
3486 load : true
35- target : worker # this has all the dep
87+ provenance : false # XXX: Without this we have untagged images in ghcr.io
3688 tags : ${{ steps.prep.outputs.tagged_image }}
37- # Using experimental GH api: https://docs.docker.com/build/ci/github-actions/cache/#cache-backend-api
38- cache-from : type=gha
39- cache-to : type=gha,mode=max
89+ cache-from : type=local,src=/tmp/.buildx-cache
90+ cache-to : type=local,dest=/tmp/.buildx-cache-new
4091
4192 - name : 🕮 Validate latest graphql schema.
4293 env :
@@ -78,6 +129,22 @@ jobs:
78129 branch : gh-pages
79130 folder : ./coverage/htmlcov
80131
132+ - name : 🐳 Docker push
133+ if : ${{ inputs.push_docker_image }}
134+ uses : docker/build-push-action@v6
135+ with :
136+ tags : ${{ steps.prep.outputs.tagged_image }}
137+ push : true
138+
139+ # Temp fix
140+ # https://github.com/docker/build-push-action/blob/master/docs/advanced/cache.md#github-cache
141+ # https://github.com/docker/build-push-action/issues/252
142+ # https://github.com/moby/buildkit/issues/1896
143+ - name : 🐳 Move docker cache (🧙 Hack fix)
144+ run : |
145+ rm -rf /tmp/.buildx-cache
146+ mv /tmp/.buildx-cache-new /tmp/.buildx-cache
147+
81148 - uses : 8398a7/action-slack@v3
82149 with :
83150 status : custom
@@ -94,3 +161,24 @@ jobs:
94161 env :
95162 SLACK_WEBHOOK_URL : ${{ secrets.SLACK_WEBHOOK }}
96163 if : always() # Pick up events even if the job fails or is canceled.
164+
165+ validate_helm :
166+ name : 🚴 Validate Helm 🚴
167+ runs-on : ubuntu-latest
168+
169+ steps :
170+ - uses : actions/checkout@main
171+
172+ - name : Install Helm
173+ uses : azure/setup-helm@v4
174+
175+ - name : 🐳 Helm dependency
176+ run : |
177+ yq --indent 0 '.dependencies | map(["helm", "repo", "add", .name, .repository] | join(" ")) | .[]' ./helm/Chart.lock | sh --
178+ helm dependency build ./helm
179+
180+ - name : 🐳 Helm lint
181+ run : helm lint ./helm --values ./helm/values-test.yaml
182+
183+ - name : 🐳 Helm template
184+ run : helm template ./helm --values ./helm/values-test.yaml
0 commit comments