diff --git a/build-frontend/action.yml b/build-frontend/action.yml index 4ebe162..31e7878 100644 --- a/build-frontend/action.yml +++ b/build-frontend/action.yml @@ -2,81 +2,106 @@ 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' - required: false + description: "Version of the app" + required: true + 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 + 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=${{ 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 }} + 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 }} @@ -89,26 +114,42 @@ 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:${{ 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=${{ 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 }} + 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: ${{ 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_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 }} + + diff --git a/build-middleware/action.yml b/build-middleware/action.yml index 959c877..35991f6 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 @@ -29,38 +32,38 @@ inputs: default: 'https://registrynpm.storefrontcloud.io' version: description: 'Version of the app' - required: false + required: true + runs: using: "composite" steps: - - 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 + # 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 }} - 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' }} + username: ${{ inputs.npm_user }} + password: ${{ inputs.npm_pass }} + + - name: Build and push + uses: docker/build-push-action@v5 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 + context: . + file: .vuestorefrontcloud/docker/middleware/Dockerfile-middleware + push: true + 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" + build-args: | + NPM_EMAIL=${{ inputs.npm_email }} + NPM_PASS=${{ inputs.npm_pass }} + NPM_USER=${{ inputs.npm_user }} + NPM_REGISTRY=${{ inputs.npm_registry }} env: NPM_EMAIL: ${{ inputs.npm_email }} NPM_PASS: ${{ inputs.npm_pass }} diff --git a/deploy/action.yml b/deploy/action.yml index dba0108..7571fe0 100644 --- a/deploy/action.yml +++ b/deploy/action.yml @@ -2,66 +2,107 @@ 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: 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: - - 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 '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 }}-${{ 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 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 +110,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 }} +