|
| 1 | +name: Publish Storybook Helm |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + push: |
| 6 | + branches: |
| 7 | + - develop |
| 8 | + - feature/deploy-storybook #TODO remove before PR is merged |
| 9 | + |
| 10 | +permissions: |
| 11 | + packages: write |
| 12 | + |
| 13 | + |
| 14 | +jobs: |
| 15 | + publish_image: |
| 16 | + name: 🐳 Publish Docker Image |
| 17 | + 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 | + 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 }}/go-ui-storybook |
| 38 | + run: | |
| 39 | + BRANCH_NAME=$(echo $GITHUB_REF_NAME | sed 's|[/:]|-|' | tr '[:upper:]' '[:lower:]' | sed 's/_/-/g' | cut -c1-100 | sed 's/-*$//') |
| 40 | + TAG="$BRANCH_NAME.$(echo $GITHUB_SHA | head -c7)" |
| 41 | + IMAGE_NAME=$(echo $IMAGE_NAME | tr '[:upper:]' '[:lower:]') |
| 42 | + echo "tagged_image_name=${IMAGE_NAME}" >> $GITHUB_OUTPUT |
| 43 | + echo "tag=${TAG}" >> $GITHUB_OUTPUT |
| 44 | + echo "tagged_image=${IMAGE_NAME}:${TAG}" >> $GITHUB_OUTPUT |
| 45 | + echo "::notice::Tagged docker image: ${IMAGE_NAME}:${TAG}" |
| 46 | +
|
| 47 | + - name: 🐳 Set up Docker Buildx |
| 48 | + id: buildx |
| 49 | + uses: docker/setup-buildx-action@v3 |
| 50 | + |
| 51 | + - name: 🐳 Cache Docker layers |
| 52 | + uses: actions/cache@v4 |
| 53 | + with: |
| 54 | + path: /tmp/.buildx-cache |
| 55 | + key: ${{ runner.os }}-buildx-${{ github.ref }} |
| 56 | + restore-keys: | |
| 57 | + ${{ runner.os }}-buildx-refs/develop |
| 58 | + ${{ runner.os }}-buildx- |
| 59 | +
|
| 60 | + - name: 🐳 Docker build |
| 61 | + uses: docker/build-push-action@v6 |
| 62 | + with: |
| 63 | + context: . |
| 64 | + builder: ${{ steps.buildx.outputs.name }} |
| 65 | + file: packages/go-ui-storybook/nginx-serve/Dockerfile |
| 66 | + target: nginx-serve |
| 67 | + load: true |
| 68 | + push: true |
| 69 | + tags: ${{ steps.prep.outputs.tagged_image }} |
| 70 | + cache-from: type=local,src=/tmp/.buildx-cache |
| 71 | + cache-to: type=local,dest=/tmp/.buildx-cache-new |
| 72 | + |
| 73 | + - name: 🐳 Move docker cache |
| 74 | + run: | |
| 75 | + rm -rf /tmp/.buildx-cache |
| 76 | + mv /tmp/.buildx-cache-new /tmp/.buildx-cache |
| 77 | +
|
| 78 | + publish_helm: |
| 79 | + name: ⎈ Publish Helm |
| 80 | + needs: publish_image |
| 81 | + runs-on: ubuntu-latest |
| 82 | + |
| 83 | + steps: |
| 84 | + - name: Checkout code |
| 85 | + uses: actions/checkout@v4 |
| 86 | + |
| 87 | + - name: Login to GitHub Container Registry |
| 88 | + uses: docker/login-action@v3 |
| 89 | + with: |
| 90 | + registry: ghcr.io |
| 91 | + username: ${{ github.actor }} |
| 92 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 93 | + |
| 94 | + - name: ⎈ Install Helm |
| 95 | + uses: azure/setup-helm@v3 |
| 96 | + |
| 97 | + - name: ⎈ Tag docker image in Helm Chart values.yaml |
| 98 | + env: |
| 99 | + IMAGE_NAME: ${{ needs.publish_image.outputs.docker_image_name }} |
| 100 | + IMAGE_TAG: ${{ needs.publish_image.outputs.docker_image_tag }} |
| 101 | + run: | |
| 102 | + # Update values.yaml with latest docker image |
| 103 | + sed -i "s|SET-BY-CICD-IMAGE|$IMAGE_NAME|" packages/go-ui-storybook/nginx-serve/helm/values.yaml |
| 104 | + sed -i "s/SET-BY-CICD-TAG/$IMAGE_TAG/" packages/go-ui-storybook/nginx-serve/helm/values.yaml |
| 105 | +
|
| 106 | + - name: ⎈ Package Helm Chart |
| 107 | + id: set-variables |
| 108 | + run: | |
| 109 | + SHA_SHORT=$(git rev-parse --short HEAD) |
| 110 | + sed -i "s/SET-BY-CICD/$SHA_SHORT/g" packages/go-ui-storybook/nginx-serve/helm/Chart.yaml |
| 111 | + helm package ./packages/go-ui-storybook/nginx-serve/helm -d .helm-charts |
| 112 | +
|
| 113 | + - name: ⎈ Push Helm Chart |
| 114 | + env: |
| 115 | + IMAGE: ${{ needs.publish_image.outputs.docker_image }} |
| 116 | + OCI_REPO: oci://ghcr.io/${{ github.repository }} |
| 117 | + run: | |
| 118 | + OCI_REPO=$(echo $OCI_REPO | tr '[:upper:]' '[:lower:]') |
| 119 | + PACKAGE_FILE=$(ls .helm-charts/*.tgz | head -n 1) |
| 120 | + echo "## 🚀 IFRC GO UI Helm Chart 🚀" >> $GITHUB_STEP_SUMMARY |
| 121 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 122 | + echo "🐳 Tagged Image: **$IMAGE**" >> $GITHUB_STEP_SUMMARY |
| 123 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 124 | + echo "⎈ Helm push output" >> $GITHUB_STEP_SUMMARY |
| 125 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 126 | + echo '```bash' >> $GITHUB_STEP_SUMMARY |
| 127 | + helm push "$PACKAGE_FILE" $OCI_REPO >> $GITHUB_STEP_SUMMARY |
| 128 | + echo '```' >> $GITHUB_STEP_SUMMARY |
0 commit comments