|
1 | | -name: Publish Helm |
| 1 | +name: Publish web app serve |
2 | 2 |
|
3 | 3 | on: |
4 | 4 | workflow_dispatch: |
|
10 | 10 | permissions: |
11 | 11 | packages: write |
12 | 12 |
|
13 | | - |
14 | 13 | jobs: |
15 | 14 | publish_image: |
16 | 15 | name: Publish Docker Image |
17 | 16 | runs-on: ubuntu-latest |
18 | | - |
19 | | - outputs: |
20 | | - docker_image_name: ${{ steps.prep.outputs.tagged_image_name }} |
21 | | - docker_image_tag: ${{ steps.prep.outputs.tag }} |
22 | | - docker_image: ${{ steps.prep.outputs.tagged_image }} |
23 | | - |
24 | 17 | steps: |
25 | | - - uses: actions/checkout@main |
26 | | - |
27 | | - - name: Login to GitHub Container Registry |
28 | | - uses: docker/login-action@v3 |
29 | | - with: |
30 | | - registry: ghcr.io |
31 | | - username: ${{ github.actor }} |
32 | | - password: ${{ secrets.GITHUB_TOKEN }} |
33 | | - |
34 | | - - name: 🐳 Prepare Docker |
35 | | - id: prep |
36 | | - env: |
37 | | - IMAGE_NAME: ghcr.io/${{ github.repository }} |
38 | | - run: | |
39 | | - BRANCH_NAME=$(echo $GITHUB_REF_NAME | sed 's|[/:]|-|' | tr '[:upper:]' '[:lower:]' | sed 's/_/-/g' | cut -c1-100 | sed 's/-*$//') |
40 | | -
|
41 | | - # XXX: Check if there is a slash in the BRANCH_NAME eg: project/add-docker |
42 | | - if [[ "$BRANCH_NAME" == *"/"* ]]; then |
43 | | - # XXX: Change the docker image package to -alpha |
44 | | - IMAGE_NAME="$IMAGE_NAME-alpha" |
45 | | - TAG="$(echo "$BRANCH_NAME" | sed 's|/|-|g').$(echo $GITHUB_SHA | head -c7)" |
46 | | - else |
47 | | - TAG="$BRANCH_NAME.$(echo $GITHUB_SHA | head -c7)" |
48 | | - fi |
49 | | -
|
50 | | - IMAGE_NAME=$(echo $IMAGE_NAME | tr '[:upper:]' '[:lower:]') |
51 | | - echo "tagged_image_name=${IMAGE_NAME}" >> $GITHUB_OUTPUT |
52 | | - echo "tag=${TAG}" >> $GITHUB_OUTPUT |
53 | | - echo "tagged_image=${IMAGE_NAME}:${TAG}" >> $GITHUB_OUTPUT |
54 | | - echo "::notice::Tagged docker image: ${IMAGE_NAME}:${TAG}" |
55 | | -
|
56 | | - - name: 🐳 Set up Docker Buildx |
57 | | - id: buildx |
58 | | - uses: docker/setup-buildx-action@v3 |
59 | | - |
60 | | - - name: 🐳 Cache Docker layers |
61 | | - uses: actions/cache@v4 |
62 | | - with: |
63 | | - path: /tmp/.buildx-cache |
64 | | - key: ${{ runner.os }}-buildx-${{ github.ref }} |
65 | | - restore-keys: | |
66 | | - ${{ runner.os }}-buildx-refs/develop |
67 | | - ${{ runner.os }}-buildx- |
| 18 | + - uses: actions/checkout@v4 |
68 | 19 |
|
69 | | - - name: 🐳 Docker build |
70 | | - uses: docker/build-push-action@v6 |
| 20 | + - name: Publish web-app-serve |
| 21 | + uses: toggle-corp/web-app-serve/.github/actions/[email protected] |
71 | 22 | with: |
72 | | - context: . |
73 | | - builder: ${{ steps.buildx.outputs.name }} |
74 | | - file: nginx-serve/Dockerfile |
75 | | - target: nginx-serve |
76 | | - load: true |
77 | | - push: true |
78 | | - tags: ${{ steps.prep.outputs.tagged_image }} |
79 | | - cache-from: type=local,src=/tmp/.buildx-cache |
80 | | - cache-to: type=local,dest=/tmp/.buildx-cache-new |
81 | | - build-args: | |
82 | | - "APP_SENTRY_TRACES_SAMPLE_RATE=0.8" |
83 | | - "APP_SENTRY_REPLAYS_SESSION_SAMPLE_RATE=0.8" |
84 | | - "APP_SENTRY_REPLAYS_ON_ERROR_SAMPLE_RATE=0.8" |
85 | | -
|
86 | | - - name: 🐳 Move docker cache |
87 | | - run: | |
88 | | - rm -rf /tmp/.buildx-cache |
89 | | - mv /tmp/.buildx-cache-new /tmp/.buildx-cache |
90 | | -
|
91 | | - publish_helm: |
92 | | - name: Publish Helm |
93 | | - needs: publish_image |
94 | | - runs-on: ubuntu-latest |
95 | | - |
96 | | - steps: |
97 | | - - name: Checkout code |
98 | | - uses: actions/checkout@v4 |
99 | | - |
100 | | - - name: Login to GitHub Container Registry |
101 | | - uses: docker/login-action@v3 |
102 | | - with: |
103 | | - registry: ghcr.io |
104 | | - username: ${{ github.actor }} |
105 | | - password: ${{ secrets.GITHUB_TOKEN }} |
106 | | - |
107 | | - - name: Install Helm |
108 | | - uses: azure/setup-helm@v3 |
109 | | - |
110 | | - - name: Tag docker image in Helm Chart values.yaml |
111 | | - env: |
112 | | - IMAGE_NAME: ${{ needs.publish_image.outputs.docker_image_name }} |
113 | | - IMAGE_TAG: ${{ needs.publish_image.outputs.docker_image_tag }} |
114 | | - run: | |
115 | | - # Update values.yaml with latest docker image |
116 | | - sed -i "s|SET-BY-CICD-IMAGE|$IMAGE_NAME|" nginx-serve/helm/values.yaml |
117 | | - sed -i "s/SET-BY-CICD-TAG/$IMAGE_TAG/" nginx-serve/helm/values.yaml |
118 | | -
|
119 | | - - name: Package Helm Chart |
120 | | - id: set-variables |
121 | | - run: | |
122 | | - # XXX: Check if there is a slash in the BRANCH_NAME eg: project/add-docker |
123 | | - if [[ "$GITHUB_REF_NAME" == *"/"* ]]; then |
124 | | - # XXX: Change the helm chart to <chart-name>-alpha |
125 | | - sed -i 's/^name: \(.*\)/name: \1-alpha/' nginx-serve/helm/Chart.yaml |
126 | | - fi |
127 | | -
|
128 | | - SHA_SHORT=$(git rev-parse --short HEAD) |
129 | | - sed -i "s/SET-BY-CICD/$SHA_SHORT/g" nginx-serve/helm/Chart.yaml |
130 | | - helm package ./nginx-serve/helm -d .helm-charts |
131 | | -
|
132 | | - - name: Push Helm Chart |
133 | | - env: |
134 | | - IMAGE: ${{ needs.publish_image.outputs.docker_image }} |
135 | | - OCI_REPO: oci://ghcr.io/${{ github.repository }} |
136 | | - run: | |
137 | | - OCI_REPO=$(echo $OCI_REPO | tr '[:upper:]' '[:lower:]') |
138 | | - PACKAGE_FILE=$(ls .helm-charts/*.tgz | head -n 1) |
139 | | - echo "# Helm Chart" >> $GITHUB_STEP_SUMMARY |
140 | | - echo "" >> $GITHUB_STEP_SUMMARY |
141 | | - echo "Tagged Image: **$IMAGE**" >> $GITHUB_STEP_SUMMARY |
142 | | - echo "" >> $GITHUB_STEP_SUMMARY |
143 | | - echo "Helm push output" >> $GITHUB_STEP_SUMMARY |
144 | | - echo "" >> $GITHUB_STEP_SUMMARY |
145 | | - echo '```bash' >> $GITHUB_STEP_SUMMARY |
146 | | - helm push "$PACKAGE_FILE" $OCI_REPO >> $GITHUB_STEP_SUMMARY |
147 | | - echo '```' >> $GITHUB_STEP_SUMMARY |
| 23 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments