From 15d0b293585f996c8c6c045843444aeec5373539 Mon Sep 17 00:00:00 2001 From: Jacob Fogolyan Date: Mon, 22 Apr 2024 14:21:14 +1000 Subject: [PATCH 1/8] chore: add frontend caching --- build-frontend/action.yml | 102 ++++++++++++++++++++++---------------- 1 file changed, 58 insertions(+), 44 deletions(-) diff --git a/build-frontend/action.yml b/build-frontend/action.yml index 4ebe162..4003129 100644 --- a/build-frontend/action.yml +++ b/build-frontend/action.yml @@ -2,71 +2,83 @@ name: Build Frontend description: Builds Storefront app docker image inputs: frontend: - description: 'Switch between Next.js and Nuxt' + description: "Switch between Next.js and Nuxt" required: false - default: 'next' + default: "next" project_name: - description: 'Project name' + description: "Project name" required: true docker_registry_url: - description: 'Docker registry url' + description: "Docker registry url" required: false - default: 'registry.vuestorefront.cloud' + default: "registry.storefrontcloud.io" + docker_registry_ref: + description: "Docker registry reference" + required: true cloud_username: - description: 'Cloud username' + description: "Cloud username" required: true cloud_password: - description: 'Cloud password' + description: "Cloud password" required: true cloud_region: - description: 'Cloud region' + description: "Cloud region" required: true npm_email: - description: 'NPM email' + description: "NPM email" required: true npm_pass: - description: 'NPM password' + description: "NPM password" required: true npm_user: - description: 'NPM user' + description: "NPM user" required: true npm_registry: - description: 'NPM registry' + description: "NPM registry" required: false - default: 'https://registrynpm.storefrontcloud.io' + default: "https://registrynpm.storefrontcloud.io" api_base_url: - description: 'Base Middleware API URL for Storefront. By default https://project_name.region.gcp.storefrontcloud.io/api' + description: "Base Middleware API URL for Storefront. By default https://project_name.region.gcp.storefrontcloud.io/api" required: false multistore_enabled: - description: 'Switch for multistore' + description: "Switch for multistore" required: false - default: 'false' + default: "false" image_provider: - description: 'Image provider name' + description: "Image provider name" required: false image_provider_upload_url: - description: 'Image Provider upload url' + description: "Image Provider upload url" required: false image_provider_fetch_url: - description: 'Image Provider fetch url' + description: "Image Provider fetch url" required: false coveo_organization_id: - description: 'Coveo organization id' + description: "Coveo organization id" required: false coveo_access_token: - description: 'Coveo access token' + description: "Coveo access token" required: false version: - description: 'Version of the app' + description: "Version of the app" required: false + runs: - using: 'composite' + using: "composite" steps: - - name: Setup node - uses: actions/setup-node@v3 + # Need buildx for caching + - name: Set up Docker Buildx + id: buildx + uses: docker/setup-buildx-action@v3 + + - name: Login Alokai Docker Registry + uses: docker/login-action@v3 with: - node-version: 18.x - - name: Build and publish docker image (Next.js frontend) + registry: ${{ inputs.docker_registry_url }} + username: ${{ inputs.npm_user }} + password: ${{ inputs.npm_pass }} + + - name: Build and push image (Next.js frontend) if: ${{ inputs.frontend == 'next' || inputs.frontend == 'nextjs' }} uses: elgohr/Publish-Docker-Github-Action@v5 with: @@ -89,26 +101,28 @@ runs: NEXT_PUBLIC_IMAGE_LOADER_FETCH_URL: ${{ inputs.image_provider_fetch_url }} NEXT_PUBLIC_COVEO_ORGANIZATION_ID: ${{ inputs.coveo_organization_id }} NEXT_PUBLIC_COVEO_ACCESS_TOKEN: ${{ inputs.coveo_access_token }} - - name: Build and publish docker image (Nuxt frontend) + + - name: Build and push if: ${{ inputs.frontend == 'nuxt' }} - uses: elgohr/Publish-Docker-Github-Action@v5 + uses: docker/build-push-action@v5 with: - name: ${{ inputs.project_name }}-storefrontcloud-io/vue-storefront:${{ inputs.version || github.sha }} - registry: ${{ inputs.docker_registry_url }} - username: ${{ inputs.cloud_username }} - password: ${{ inputs.cloud_password }} - dockerfile: .vuestorefrontcloud/docker/nuxtjs/Dockerfile-frontend - buildoptions: --compress - buildargs: NPM_EMAIL,NPM_PASS,NPM_USER,NPM_REGISTRY,NUXT_PUBLIC_API_BASE_URL,NUXT_PUBLIC_MULTISTORE_ENABLED,NUXT_IMAGE_PROVIDER,NUXT_PUBLIC_IMAGE_LOADER_FETCH_URL,NUXT_PUBLIC_IMAGE_LOADER_UPLOAD_URL,NUXT_PUBLIC_COVEO_ORGANIZATION_ID,NUXT_PUBLIC_COVEO_ACCESS_TOKEN + context: . + file: .vuestorefrontcloud/docker/nuxtjs/Dockerfile-frontend + push: true + tags: ${{ inputs.docker_registry_ref }}/vue-storefront:${{ github.sha }} + # Inline cache + cache-from: "type=registry,ref=${{ inputs.docker_registry_ref }}/vue-storefront:${{ inputs.project_name }}-buildcache" + cache-to: "type=registry,ref=${{ inputs.docker_registry_ref }}/vue-storefront:${{ inputs.project_name }}-buildcache,mode=max" + build-args: | + NPM_EMAIL=${{ inputs.npm_email }} + NPM_PASS=${{ inputs.npm_pass }} + NPM_USER=${{ inputs.npm_user }} + NPM_REGISTRY=https://registrynpm.storefrontcloud.io + NUXT_PUBLIC_API_BASE_URL: https://${{ inputs.project_name }}.${{ inputs.cloud_region }}.gcp.storefrontcloud.io/api/ env: NPM_EMAIL: ${{ inputs.npm_email }} NPM_PASS: ${{ inputs.npm_pass }} NPM_USER: ${{ inputs.npm_user }} - NPM_REGISTRY: ${{ inputs.npm_registry }} - NUXT_PUBLIC_API_BASE_URL: ${{ inputs.api_base_url || format('https://{0}.{1}.{2}/api', inputs.project_name, inputs.cloud_region, 'gcp.storefrontcloud.io') }} - NUXT_PUBLIC_MULTISTORE_ENABLED: ${{ inputs.multistore_enabled }} - NUXT_IMAGE_PROVIDER: ${{ inputs.image_provider }} - NUXT_PUBLIC_IMAGE_LOADER_UPLOAD_URL: ${{ inputs.image_provider_upload_url }} - NUXT_PUBLIC_IMAGE_LOADER_FETCH_URL: ${{ inputs.image_provider_fetch_url }} - NUXT_PUBLIC_COVEO_ORGANIZATION_ID: ${{ inputs.coveo_organization_id }} - NUXT_PUBLIC_COVEO_ACCESS_TOKEN: ${{ inputs.coveo_access_token }} + NPM_REGISTRY: https://registrynpm.storefrontcloud.io + NUXT_PUBLIC_API_BASE_URL: https://${{ inputs.project_name }}.${{ inputs.cloud_region }}.gcp.storefrontcloud.io/api/ + From 77c72ce48bbbc87805220c42be100d775d6a6ab1 Mon Sep 17 00:00:00 2001 From: Jacob Fogolyan Date: Mon, 22 Apr 2024 17:52:33 +1000 Subject: [PATCH 2/8] feat: add middleware caching --- build-middleware/action.yml | 49 ++++++++++++++++++++++++++++++------- 1 file changed, 40 insertions(+), 9 deletions(-) diff --git a/build-middleware/action.yml b/build-middleware/action.yml index 959c877..5026bc7 100644 --- a/build-middleware/action.yml +++ b/build-middleware/action.yml @@ -7,7 +7,10 @@ inputs: docker_registry_url: description: 'Docker registry url' required: false - default: 'registry.vuestorefront.cloud' + default: "registry.storefrontcloud.io" + docker_registry_ref: + description: "Docker registry reference" + required: true cloud_username: description: 'Cloud username' required: true @@ -33,23 +36,29 @@ inputs: runs: using: "composite" steps: + # Need buildx for caching + - name: Set up Docker Buildx + id: buildx + uses: docker/setup-buildx-action@v3 + + - name: Login Alokai Docker Registry + uses: docker/login-action@v3 + with: + registry: ${{ inputs.docker_registry_url }} + username: ${{ inputs.npm_user }} + password: ${{ inputs.npm_pass }} + - name: Setup node uses: actions/setup-node@v3 with: node-version: 18.x + - name: Encode Basic Auth id: base64-auth shell: bash run: | echo "BASIC_AUTH_TOKEN=$(echo -n ${{ inputs.cloud_username }}:${{ inputs.cloud_password }} | base64 -w 0)" >> "$GITHUB_OUTPUT" - - name: Check for existing image - id: check-existing-image - uses: javajawa/check-registry-for-image@v2 - with: - registry: ${{ inputs.docker_registry_url }} - auth: "Basic ${{ steps.base64-auth.outputs.BASIC_AUTH_TOKEN }}" - repository: ${{ inputs.project_name }}-storefrontcloud-io/vue-storefront-middleware - tag: ${{ inputs.version || github.sha }} + - name: Build and publish docker image (middleware) uses: elgohr/Publish-Docker-Github-Action@v5 if: ${{ steps.check-existing-image.outputs.exists == 'false' }} @@ -66,3 +75,25 @@ runs: NPM_PASS: ${{ inputs.npm_pass }} NPM_USER: ${{ inputs.npm_user }} NPM_REGISTRY: ${{ inputs.npm_registry }} + + - name: Build and push + uses: docker/build-push-action@v5 + with: + context: . + file: .vuestorefrontcloud/docker/middleware/Dockerfile-middleware + push: true + tags: ${{ inputs.docker_registry_ref }}/vue-storefront-middleware:${{ github.sha }} + # Inline cache + cache-from: "type=registry,ref=${{ inputs.docker_registry_ref }}/vue-storefront-middleware:${{ inputs.project_name }}-buildcache" + cache-to: "type=registry,ref=${{ inputs.docker_registry_ref }}/vue-storefront-middleware:${{ inputs.project_name }}-buildcache,mode=max" + build-args: | + NPM_EMAIL=${{ inputs.npm_email }} + NPM_PASS=${{ inputs.npm_pass }} + NPM_USER=${{ inputs.npm_user }} + NPM_REGISTRY=https://registrynpm.storefrontcloud.io + env: + NPM_EMAIL: ${{ inputs.npm_email }} + NPM_PASS: ${{ inputs.npm_pass }} + NPM_USER: ${{ inputs.npm_user }} + NPM_REGISTRY: https://registrynpm.storefrontcloud.io + From 99408c84da807b90ab0ead3bda869a75ae9e1bd7 Mon Sep 17 00:00:00 2001 From: Jacob Fogolyan Date: Mon, 22 Apr 2024 17:53:37 +1000 Subject: [PATCH 3/8] chore: update deploy script --- deploy/action.yml | 85 ++++++++++++++++++++++++++++------------------- 1 file changed, 51 insertions(+), 34 deletions(-) diff --git a/deploy/action.yml b/deploy/action.yml index dba0108..ce2b68c 100644 --- a/deploy/action.yml +++ b/deploy/action.yml @@ -2,66 +2,82 @@ name: Deploy Storefront description: Builds Middleware app docker image inputs: project_name: - description: 'Project name' + description: "Project name" required: true docker_registry_url: - description: 'Docker registry url' + description: "Docker registry url" required: false - default: 'registry.vuestorefront.cloud' + default: "registry.vuestorefront.cloud" cloud_username: - description: 'Cloud username' + description: "Cloud username" required: true cloud_password: - description: 'Cloud password' + description: "Cloud password" required: true cloud_region: - description: 'Cloud region' + description: "Cloud region" required: true console_api_url: - description: 'URI for Vue Storefront Console API' + description: "URI for Vue Storefront Console API" required: false - default: 'https://api.platform.vuestorefront.io' + default: "https://api.platform.vuestorefront.io" version: - description: 'Version of the app' + description: "Version of the app" required: false runs: using: "composite" steps: - - uses: chrnorm/deployment-action@releases/v2 + - uses: chrnorm/deployment-action@v2 name: Create GitHub deployment id: deployment with: - token: '${{ github.token }}' + token: "${{ github.token }}" environment-url: https://${{ inputs.project_name }}.${{ inputs.cloud_region }}.gcp.storefrontcloud.io - environment: production initial-status: in_progress - - - name: Deploy Frontend App (${{ inputs.project_name }}.${{ inputs.cloud_region }}.gcp.storefrontcloud.io) - uses: fjogeleit/http-request-action@v1 - with: - url: "${{ inputs.console_api_url }}/cloud/instances/${{ inputs.project_name }}-${{ inputs.cloud_region }}-gcp-storefrontcloud-io/deploy" - method: "PATCH" - customHeaders: '{"Content-Type":"application/json"}' - data: '{ "cloudUserId":"${{ inputs.cloud_username }}", "cloudUserPassword":"${{ inputs.cloud_password }}", "dockerImageHash":"${{ inputs.version || github.sha }}" }' - timeout: 60000 - - - name: Deploy Middleware (${{ inputs.project_name }}.${{ inputs.cloud_region }}.gcp.storefrontcloud.io) - uses: fjogeleit/http-request-action@v1 - with: - url: "${{ inputs.console_api_url }}/cloud/instances/${{ inputs.project_name }}-${{ inputs.cloud_region }}-gcp-storefrontcloud-io/deploy" - method: "PATCH" - customHeaders: '{"Content-Type":"application/json"}' - data: '{ "middleware":true, "cloudUserId":"${{ inputs.cloud_username }}", "cloudUserPassword":"${{ inputs.cloud_password }}", "dockerImageHash":"${{ inputs.version || github.sha }}", "middlewareData":{ "path":"/api/", "port":4000, "has_base_path":false } }' - timeout: 60000 + - name: Deploy on ${{ inputs.project_name }}.${{ inputs.cloud_region }}.gcp.storefrontcloud.io + shell: bash + run: | + tmpfile=$(mktemp /tmp/farmer-output.XXXXXXX) + FARMERCODE=`curl --write-out '%{http_code}' --silent --output "$tmpfile" \ + -H 'X-User-Id: ${{ inputs.cloud_username }}' \ + -H 'X-Api-Key: ${{ inputs.cloud_password }}' \ + -H 'Content-Type: application/json' \ + -X PATCH -d '{ + "front_version":"${{ github.sha }}", + "additional_apps":{ + "enabled": true, + "apps":[{ + "name":"middleware", + "tag":"${{ github.sha }}", + "image":"${{ inputs.docker_registry_url }}/${{ inputs.project_name }}-storefrontcloud-io/vue-storefront-middleware", + "path":"/api/", + "port":"4000", + "has_base_path":false, + "health_check": { + "enabled": true, + "path": "/healthz" + } + }] + } + }' https://farmer.storefrontcloud.io/instance/${{ inputs.project_name }}-${{ inputs.cloud_region }}-gcp-storefrontcloud-io` + cat "$tmpfile" + rm "$tmpfile" + if [[ $FARMERCODE<"400" && $FARMERCODE -ge "200" ]] + then + echo "farmer deploy: SUCCESS"; + else + echo "farmer deploy FAILED ❌ with code $FARMERCODE"; + exit 1; + fi - name: Update deployment status (success) if: success() uses: chrnorm/deployment-status@releases/v2 with: - token: '${{ github.token }}' + token: "${{ github.token }}" environment-url: https://${{ inputs.project_name }}.${{ inputs.cloud_region }}.gcp.storefrontcloud.io - state: 'success' + state: "success" description: Congratulations! The deploy is done. deployment-id: ${{ steps.deployment.outputs.deployment_id }} @@ -69,8 +85,9 @@ runs: if: failure() uses: chrnorm/deployment-status@releases/v2 with: - token: '${{ github.token }}' + token: "${{ github.token }}" environment-url: https://${{ inputs.project_name }}.${{ inputs.cloud_region }}.gcp.storefrontcloud.io description: Unfortunately, the instance hasn't been updated. - state: 'failure' + state: "failure" deployment-id: ${{ steps.deployment.outputs.deployment_id }} + From ebc2d544d0d6fbea35fcfb134c54ccd533c74a10 Mon Sep 17 00:00:00 2001 From: Jacob Fogolyan Date: Wed, 24 Apr 2024 10:35:14 +1000 Subject: [PATCH 4/8] chore: change tag name to version and fix curl req --- build-frontend/action.yml | 36 ++++++++++++++++++++++---------- build-middleware/action.yml | 33 +++-------------------------- deploy/action.yml | 41 ++++++++++++++++--------------------- 3 files changed, 46 insertions(+), 64 deletions(-) diff --git a/build-frontend/action.yml b/build-frontend/action.yml index 4003129..abd801d 100644 --- a/build-frontend/action.yml +++ b/build-frontend/action.yml @@ -61,7 +61,7 @@ inputs: required: false version: description: "Version of the app" - required: false + required: true runs: using: "composite" @@ -80,15 +80,28 @@ runs: - name: Build and push image (Next.js frontend) if: ${{ inputs.frontend == 'next' || inputs.frontend == 'nextjs' }} - uses: elgohr/Publish-Docker-Github-Action@v5 + uses: docker/build-push-action@v5 with: - name: ${{ inputs.project_name }}-storefrontcloud-io/vue-storefront:${{ inputs.version || github.sha }} - registry: ${{ inputs.docker_registry_url }} - username: ${{ inputs.cloud_username }} - password: ${{ inputs.cloud_password }} - dockerfile: .vuestorefrontcloud/docker/nextjs/Dockerfile-frontend - buildoptions: --compress - buildargs: NPM_EMAIL,NPM_PASS,NPM_USER,NPM_REGISTRY,NEXT_PUBLIC_API_BASE_URL,NEXT_PUBLIC_MULTISTORE_ENABLED,NEXT_IMAGE_PROVIDER,NEXT_PUBLIC_IMAGE_LOADER_FETCH_URL,NEXT_PUBLIC_IMAGE_LOADER_UPLOAD_URL,NEXT_PUBLIC_COVEO_ORGANIZATION_ID,NEXT_PUBLIC_COVEO_ACCESS_TOKEN + context: . + file: .vuestorefrontcloud/docker/nextjs/Dockerfile-frontend + push: true + tags: ${{ inputs.docker_registry_ref }}/vue-storefront:${{ inputs.version }} + # Inline cache + cache-from: "type=registry,ref=${{ inputs.docker_registry_ref }}/vue-storefront:${{ inputs.project_name }}-buildcache" + cache-to: "type=registry,ref=${{ inputs.docker_registry_ref }}/vue-storefront:${{ inputs.project_name }}-buildcache,mode=max" + build-args: | + NPM_EMAIL=${{ inputs.npm_email }} + NPM_PASS=${{ inputs.npm_pass }} + NPM_USER=${{ inputs.npm_user }} + NPM_REGISTRY=https://registrynpm.storefrontcloud.io + NEXT_PUBLIC_API_BASE_URL=${{ inputs.api_base_url || format('https://{0}.{1}.{2}/api', inputs.project_name, inputs.cloud_region, 'gcp.storefrontcloud.io') }} + NEXT_PUBLIC_MULTISTORE_ENABLED=${{ inputs.multistore_enabled }} + NEXT_IMAGE_PROVIDER=${{ inputs.image_provider }} + NEXT_PUBLIC_IMAGE_LOADER_UPLOAD_URL=${{ inputs.image_provider_upload_url }} + NEXT_PUBLIC_IMAGE_LOADER_FETCH_URL=${{ inputs.image_provider_fetch_url }} + NEXT_PUBLIC_COVEO_ORGANIZATION_ID=${{ inputs.coveo_organization_id }} + NEXT_PUBLIC_COVEO_ACCESS_TOKEN=${{ inputs.coveo_access_token }} + env: NPM_EMAIL: ${{ inputs.npm_email }} NPM_PASS: ${{ inputs.npm_pass }} @@ -109,7 +122,7 @@ runs: context: . file: .vuestorefrontcloud/docker/nuxtjs/Dockerfile-frontend push: true - tags: ${{ inputs.docker_registry_ref }}/vue-storefront:${{ github.sha }} + tags: ${{ inputs.docker_registry_ref }}/vue-storefront:${{ inputs.version }} # Inline cache cache-from: "type=registry,ref=${{ inputs.docker_registry_ref }}/vue-storefront:${{ inputs.project_name }}-buildcache" cache-to: "type=registry,ref=${{ inputs.docker_registry_ref }}/vue-storefront:${{ inputs.project_name }}-buildcache,mode=max" @@ -118,7 +131,7 @@ runs: NPM_PASS=${{ inputs.npm_pass }} NPM_USER=${{ inputs.npm_user }} NPM_REGISTRY=https://registrynpm.storefrontcloud.io - NUXT_PUBLIC_API_BASE_URL: https://${{ inputs.project_name }}.${{ inputs.cloud_region }}.gcp.storefrontcloud.io/api/ + NUXT_PUBLIC_API_BASE_URL=https://${{ inputs.project_name }}.${{ inputs.cloud_region }}.gcp.storefrontcloud.io/api/ env: NPM_EMAIL: ${{ inputs.npm_email }} NPM_PASS: ${{ inputs.npm_pass }} @@ -126,3 +139,4 @@ runs: NPM_REGISTRY: https://registrynpm.storefrontcloud.io NUXT_PUBLIC_API_BASE_URL: https://${{ inputs.project_name }}.${{ inputs.cloud_region }}.gcp.storefrontcloud.io/api/ + diff --git a/build-middleware/action.yml b/build-middleware/action.yml index 5026bc7..d184d8b 100644 --- a/build-middleware/action.yml +++ b/build-middleware/action.yml @@ -32,7 +32,8 @@ inputs: default: 'https://registrynpm.storefrontcloud.io' version: description: 'Version of the app' - required: false + required: true + runs: using: "composite" steps: @@ -48,41 +49,13 @@ runs: username: ${{ inputs.npm_user }} password: ${{ inputs.npm_pass }} - - name: Setup node - uses: actions/setup-node@v3 - with: - node-version: 18.x - - - name: Encode Basic Auth - id: base64-auth - shell: bash - run: | - echo "BASIC_AUTH_TOKEN=$(echo -n ${{ inputs.cloud_username }}:${{ inputs.cloud_password }} | base64 -w 0)" >> "$GITHUB_OUTPUT" - - - name: Build and publish docker image (middleware) - uses: elgohr/Publish-Docker-Github-Action@v5 - if: ${{ steps.check-existing-image.outputs.exists == 'false' }} - with: - name: ${{ inputs.project_name }}-storefrontcloud-io/vue-storefront-middleware:${{ inputs.version || github.sha }} - registry: ${{ inputs.docker_registry_url }} - username: ${{ inputs.cloud_username }} - password: ${{ inputs.cloud_password }} - dockerfile: .vuestorefrontcloud/docker/middleware/Dockerfile-middleware - buildoptions: --compress - buildargs: NPM_EMAIL,NPM_PASS,NPM_USER,NPM_REGISTRY - env: - NPM_EMAIL: ${{ inputs.npm_email }} - NPM_PASS: ${{ inputs.npm_pass }} - NPM_USER: ${{ inputs.npm_user }} - NPM_REGISTRY: ${{ inputs.npm_registry }} - - name: Build and push uses: docker/build-push-action@v5 with: context: . file: .vuestorefrontcloud/docker/middleware/Dockerfile-middleware push: true - tags: ${{ inputs.docker_registry_ref }}/vue-storefront-middleware:${{ github.sha }} + tags: ${{ inputs.docker_registry_ref }}/vue-storefront-middleware:${{ inputs.version }} # Inline cache cache-from: "type=registry,ref=${{ inputs.docker_registry_ref }}/vue-storefront-middleware:${{ inputs.project_name }}-buildcache" cache-to: "type=registry,ref=${{ inputs.docker_registry_ref }}/vue-storefront-middleware:${{ inputs.project_name }}-buildcache,mode=max" diff --git a/deploy/action.yml b/deploy/action.yml index ce2b68c..c5c286b 100644 --- a/deploy/action.yml +++ b/deploy/action.yml @@ -23,11 +23,12 @@ inputs: default: "https://api.platform.vuestorefront.io" version: description: "Version of the app" - required: false + required: true runs: using: "composite" steps: + - uses: chrnorm/deployment-action@v2 name: Create GitHub deployment id: deployment @@ -35,42 +36,36 @@ runs: token: "${{ github.token }}" environment-url: https://${{ inputs.project_name }}.${{ inputs.cloud_region }}.gcp.storefrontcloud.io initial-status: in_progress + - name: Deploy on ${{ inputs.project_name }}.${{ inputs.cloud_region }}.gcp.storefrontcloud.io shell: bash run: | tmpfile=$(mktemp /tmp/farmer-output.XXXXXXX) - FARMERCODE=`curl --write-out '%{http_code}' --silent --output "$tmpfile" \ - -H 'X-User-Id: ${{ inputs.cloud_username }}' \ - -H 'X-Api-Key: ${{ inputs.cloud_password }}' \ + FARMERCODE=$(curl --write-out '%{http_code}' --silent --output "$tmpfile" \ -H 'Content-Type: application/json' \ -X PATCH -d '{ - "front_version":"${{ github.sha }}", - "additional_apps":{ - "enabled": true, - "apps":[{ - "name":"middleware", - "tag":"${{ github.sha }}", - "image":"${{ inputs.docker_registry_url }}/${{ inputs.project_name }}-storefrontcloud-io/vue-storefront-middleware", - "path":"/api/", - "port":"4000", - "has_base_path":false, - "health_check": { - "enabled": true, - "path": "/healthz" - } - }] - } - }' https://farmer.storefrontcloud.io/instance/${{ inputs.project_name }}-${{ inputs.cloud_region }}-gcp-storefrontcloud-io` + "cloudUserId": "${{ inputs.cloud_username }}", + "cloudUserPassword": "${{ inputs.cloud_password }}", + "dockerImageHash": "${{ inputs.version }}", + "middlewareData": { + "path": "/api/", + "port": 4000, + "has_base_path": false, + "health_check": { + "enabled": true, + "path": "/healthz" + } + } + }' https://api.console.vuestorefront.io/cloud/instances/${{ inputs.project_name }}-${{ inputs.cloud_region }}-gcp-storefrontcloud-io/deploy) cat "$tmpfile" rm "$tmpfile" - if [[ $FARMERCODE<"400" && $FARMERCODE -ge "200" ]] + if [[ $FARMERCODE -lt 400 && $FARMERCODE -ge 200 ]] then echo "farmer deploy: SUCCESS"; else echo "farmer deploy FAILED ❌ with code $FARMERCODE"; exit 1; fi - - name: Update deployment status (success) if: success() uses: chrnorm/deployment-status@releases/v2 From e80c2cd8e81d32ce1388ae7d7513d42519cf6411 Mon Sep 17 00:00:00 2001 From: Jacob Fogolyan Date: Wed, 24 Apr 2024 11:42:50 +1000 Subject: [PATCH 5/8] chore: re-add nuxt env vars --- build-frontend/action.yml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/build-frontend/action.yml b/build-frontend/action.yml index abd801d..b5863b7 100644 --- a/build-frontend/action.yml +++ b/build-frontend/action.yml @@ -132,11 +132,24 @@ runs: NPM_USER=${{ inputs.npm_user }} NPM_REGISTRY=https://registrynpm.storefrontcloud.io NUXT_PUBLIC_API_BASE_URL=https://${{ inputs.project_name }}.${{ inputs.cloud_region }}.gcp.storefrontcloud.io/api/ + NUXT_PUBLIC_MULTISTORE_ENABLED=${{ inputs.multistore_enabled }} + NUXT_IMAGE_PROVIDER=${{ inputs.image_provider }} + NUXT_PUBLIC_IMAGE_LOADER_UPLOAD_URL=${{ inputs.image_provider_upload_url }} + NUXT_PUBLIC_IMAGE_LOADER_FETCH_URL=${{ inputs.image_provider_fetch_url }} + NUXT_PUBLIC_COVEO_ORGANIZATION_ID=${{ inputs.coveo_organization_id }} + NUXT_PUBLIC_COVEO_ACCESS_TOKEN=${{ inputs.coveo_access_token }} + env: NPM_EMAIL: ${{ inputs.npm_email }} NPM_PASS: ${{ inputs.npm_pass }} NPM_USER: ${{ inputs.npm_user }} NPM_REGISTRY: https://registrynpm.storefrontcloud.io NUXT_PUBLIC_API_BASE_URL: https://${{ inputs.project_name }}.${{ inputs.cloud_region }}.gcp.storefrontcloud.io/api/ + NUXT_PUBLIC_MULTISTORE_ENABLED: ${{ inputs.multistore_enabled }} + NUXT_IMAGE_PROVIDER: ${{ inputs.image_provider }} + NUXT_PUBLIC_IMAGE_LOADER_UPLOAD_URL: ${{ inputs.image_provider_upload_url }} + NUXT_PUBLIC_IMAGE_LOADER_FETCH_URL: ${{ inputs.image_provider_fetch_url }} + NUXT_PUBLIC_COVEO_ORGANIZATION_ID: ${{ inputs.coveo_organization_id }} + NUXT_PUBLIC_COVEO_ACCESS_TOKEN: ${{ inputs.coveo_access_token }} From 3799929692d217a432f88c450168b554e2930fb2 Mon Sep 17 00:00:00 2001 From: Jacob Fogolyan Date: Sat, 8 Jun 2024 00:21:02 +1000 Subject: [PATCH 6/8] chore: build caching for middleware action --- build-middleware/action.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/build-middleware/action.yml b/build-middleware/action.yml index d184d8b..29c7094 100644 --- a/build-middleware/action.yml +++ b/build-middleware/action.yml @@ -69,4 +69,3 @@ runs: NPM_PASS: ${{ inputs.npm_pass }} NPM_USER: ${{ inputs.npm_user }} NPM_REGISTRY: https://registrynpm.storefrontcloud.io - From 81b509e7d3600fa03bd48d40dbc44efc7ac94a10 Mon Sep 17 00:00:00 2001 From: Jacob Fogolyan Date: Sat, 8 Jun 2024 00:21:20 +1000 Subject: [PATCH 7/8] chore: modify deploy script to be more legible --- deploy/action.yml | 82 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 56 insertions(+), 26 deletions(-) diff --git a/deploy/action.yml b/deploy/action.yml index c5c286b..7571fe0 100644 --- a/deploy/action.yml +++ b/deploy/action.yml @@ -24,7 +24,35 @@ inputs: version: description: "Version of the app" required: true - + middleware_data: + description: "Middleware Data" + required: false + default: '' + additional_apps: + description: "Additional Apps Data (Excluding Middleware)" + required: false + default: '' + ## Middleware inputs + middleware_path: + description: "Route to middleware" + required: false + default: "/api/" + middleware_port: + description: "Port of middleware" + required: false + default: 4000 + middleware_base_path: + description: "The base path of middleware" + required: false + default: false + middleware_heath_check_enabled: + description: "Health check enabled" + required: false + default: true + middleware_health_check_path: + description: "health check route" + required: false + default: "/healthz" runs: using: "composite" steps: @@ -40,32 +68,34 @@ runs: - name: Deploy on ${{ inputs.project_name }}.${{ inputs.cloud_region }}.gcp.storefrontcloud.io shell: bash run: | - tmpfile=$(mktemp /tmp/farmer-output.XXXXXXX) - FARMERCODE=$(curl --write-out '%{http_code}' --silent --output "$tmpfile" \ - -H 'Content-Type: application/json' \ - -X PATCH -d '{ - "cloudUserId": "${{ inputs.cloud_username }}", - "cloudUserPassword": "${{ inputs.cloud_password }}", - "dockerImageHash": "${{ inputs.version }}", - "middlewareData": { - "path": "/api/", - "port": 4000, - "has_base_path": false, - "health_check": { - "enabled": true, - "path": "/healthz" + tmpfile=$(mktemp /tmp/farmer-output.XXXXXXX) + FARMERCODE=$(curl --write-out '%{http_code}' --silent --output "$tmpfile" \ + -H 'Content-Type: application/json' \ + -X PATCH -d '{ + "cloudUserId": "${{ inputs.cloud_username }}", + "cloudUserPassword": "${{ inputs.cloud_password }}", + "dockerImageHash": "${{ inputs.version }}", + "middlewareData": { + "path": "${{ inputs.middleware_path }}", + "port": ${{ inputs.middleware_port }}, + "has_base_path": ${{ inputs.middleware_base_path }}, + "health_check": { + "enabled": ${{ inputs.middleware_heath_check_enabled }}, + "path": "${{ inputs.middleware_health_check_path }}" + } } - } - }' https://api.console.vuestorefront.io/cloud/instances/${{ inputs.project_name }}-${{ inputs.cloud_region }}-gcp-storefrontcloud-io/deploy) - cat "$tmpfile" - rm "$tmpfile" - if [[ $FARMERCODE -lt 400 && $FARMERCODE -ge 200 ]] - then - echo "farmer deploy: SUCCESS"; - else - echo "farmer deploy FAILED ❌ with code $FARMERCODE"; - exit 1; - fi + + }' https://api.console.vuestorefront.io/cloud/instances/${{ inputs.project_name }}-${{ env.REGION }}-gcp-storefrontcloud-io/deploy) + cat "$tmpfile" + rm "$tmpfile" + if [[ $FARMERCODE -lt 400 && $FARMERCODE -ge 200 ]] + then + echo "farmer deploy: SUCCESS"; + else + echo "farmer deploy FAILED ❌ with code $FARMERCODE"; + exit 1; + fi + - name: Update deployment status (success) if: success() uses: chrnorm/deployment-status@releases/v2 From fd3987d0a02360d5b2fc10670513efea03cd290e Mon Sep 17 00:00:00 2001 From: Jacob Fogolyan Date: Fri, 14 Jun 2024 00:44:44 +1000 Subject: [PATCH 8/8] chore: set npm registry as inputs --- build-frontend/action.yml | 6 +++--- build-middleware/action.yml | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/build-frontend/action.yml b/build-frontend/action.yml index b5863b7..31e7878 100644 --- a/build-frontend/action.yml +++ b/build-frontend/action.yml @@ -93,7 +93,7 @@ runs: NPM_EMAIL=${{ inputs.npm_email }} NPM_PASS=${{ inputs.npm_pass }} NPM_USER=${{ inputs.npm_user }} - NPM_REGISTRY=https://registrynpm.storefrontcloud.io + NPM_REGISTRY=${{ inputs.npm_registry }} NEXT_PUBLIC_API_BASE_URL=${{ inputs.api_base_url || format('https://{0}.{1}.{2}/api', inputs.project_name, inputs.cloud_region, 'gcp.storefrontcloud.io') }} NEXT_PUBLIC_MULTISTORE_ENABLED=${{ inputs.multistore_enabled }} NEXT_IMAGE_PROVIDER=${{ inputs.image_provider }} @@ -130,7 +130,7 @@ runs: NPM_EMAIL=${{ inputs.npm_email }} NPM_PASS=${{ inputs.npm_pass }} NPM_USER=${{ inputs.npm_user }} - NPM_REGISTRY=https://registrynpm.storefrontcloud.io + NPM_REGISTRY=${{ inputs.npm_registry }} NUXT_PUBLIC_API_BASE_URL=https://${{ inputs.project_name }}.${{ inputs.cloud_region }}.gcp.storefrontcloud.io/api/ NUXT_PUBLIC_MULTISTORE_ENABLED=${{ inputs.multistore_enabled }} NUXT_IMAGE_PROVIDER=${{ inputs.image_provider }} @@ -143,7 +143,7 @@ runs: NPM_EMAIL: ${{ inputs.npm_email }} NPM_PASS: ${{ inputs.npm_pass }} NPM_USER: ${{ inputs.npm_user }} - NPM_REGISTRY: https://registrynpm.storefrontcloud.io + NPM_REGISTRY: ${{ inputs.npm_registry }} NUXT_PUBLIC_API_BASE_URL: https://${{ inputs.project_name }}.${{ inputs.cloud_region }}.gcp.storefrontcloud.io/api/ NUXT_PUBLIC_MULTISTORE_ENABLED: ${{ inputs.multistore_enabled }} NUXT_IMAGE_PROVIDER: ${{ inputs.image_provider }} diff --git a/build-middleware/action.yml b/build-middleware/action.yml index 29c7094..35991f6 100644 --- a/build-middleware/action.yml +++ b/build-middleware/action.yml @@ -63,9 +63,9 @@ runs: NPM_EMAIL=${{ inputs.npm_email }} NPM_PASS=${{ inputs.npm_pass }} NPM_USER=${{ inputs.npm_user }} - NPM_REGISTRY=https://registrynpm.storefrontcloud.io + NPM_REGISTRY=${{ inputs.npm_registry }} env: NPM_EMAIL: ${{ inputs.npm_email }} NPM_PASS: ${{ inputs.npm_pass }} NPM_USER: ${{ inputs.npm_user }} - NPM_REGISTRY: https://registrynpm.storefrontcloud.io + NPM_REGISTRY: ${{ inputs.npm_registry }}