Skip to content

Commit

Permalink
ci(ES-665): stripe ct actions (#20)
Browse files Browse the repository at this point in the history
* ci(ES-665): add stripe-ct action

* ci: build and deploy actions

* update gh actions

* Apply suggestions from code review

Co-authored-by: Mateusz Gostański <[email protected]>

* apply review feedback

* refactor

* fix build action

* fix deploy action

* fix deploy tags

* fix build step outputs

* fix build envs

* update readme

* Apply suggestions from code review

Co-authored-by: Mateusz Gostański <[email protected]>

---------

Co-authored-by: Mateusz Gostański <[email protected]>
  • Loading branch information
WojtekTheWebDev and grixu authored Jul 30, 2024
1 parent 91b3ec6 commit b48b7f3
Show file tree
Hide file tree
Showing 4 changed files with 260 additions and 15 deletions.
58 changes: 58 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,36 @@ with:
- `npm_registry`: URL to the private NPM registry. Optional field. Defaults to `https://registrynpm.storefrontcloud.io`.
- `version`: Version that will be used for docker image tag. Example: 2.3.0, 3.1.0-rc.1. If not passed, github.sha will be used

### build-stripe-ct

```yaml
uses: vuestorefront/storefront-deployment/build-stripe-ct
with:
project_name: ${{ secrets.PROJECT_NAME }}
cloud_username: ${{ secrets.CLOUD_USERNAME }}
cloud_password: ${{ secrets.CLOUD_PASSWORD }}
docker_registry_url: 'registry.vuestorefront.cloud'
version: 2.3.0
```

**Input Parameters:**

- `project_name`: Project name in Console. Required field.
- `cloud_username`: Cloud API and Docker registry username. Required field.
- `cloud_password`: Cloud API and Docker registry password. Required field.
- `npm_email`: Email address required for logging into the private NPM registry. Required field.
- `npm_user`: Username for the private NPM registry. Required field.
- `npm_pass`: Password for the private NPM registry. Required field.
- `docker_registry_url`: URL to the Docker image registry. Optional field. Defaults to `registry.vuestorefront.cloud`.
- `npm_registry`: URL to the private NPM registry. Optional field. Defaults to `https://registrynpm.storefrontcloud.io`.
- `version`: Version that will be used for docker image tag. Example: 2.3.0, 3.1.0-rc.1. If not passed, github.sha will be used
- `extension_module_name`: Extension module name. It’s used as the name of the docker image and path where the api is available. Default value is `ct-stripe-extension`.
- `extension_module_port`: Port of the extension module. Default value is `8080`.
- `extension_module_config`: Configuration for the extension module. Required field.
- `notification_module_name`: Notification module name. It’s used as the name of the docker image and path where the api is available. Default value is `ct-stripe-notification`.
- `notification_module_port`: Port of the notification module. Default value is `8081`.
- `notification_module_config`: Configuration for the notification module. Required field.

### deploy

```yaml
Expand All @@ -97,3 +127,31 @@ with:
- `docker_registry_url`: URL to the Docker image registry. Optional field. Defaults to `registry.vuestorefront.cloud`.
- `console_api_url`: URL to the Console. Optional field. Defaults to `https://api.platform.vuestorefront.io`.
- `version`: Docker image tag that will be deployed. Example: 2.3.0, 3.1.0-rc.1. If not passed, github.sha will be used

### deploy/stripe-ct

```yaml
uses: vuestorefront/storefront-deployment/deploy/stripe-ct
with:
project_name: ${{ secrets.PROJECT_NAME }}
cloud_username: ${{ secrets.CLOUD_USERNAME }}
cloud_password: ${{ secrets.CLOUD_PASSWORD }}
cloud_region: ${{ secrets.CLOUD_REGION }}
docker_registry_url: 'registry.vuestorefront.cloud'
console_api: 'https://api.platform.vuestorefront.io'
version: 2.3.0
```

**Input Parameters:**

- `project_name`: Project name in Console. Required field.
- `cloud_username`: Cloud API and Docker registry username. Required field.
- `cloud_password`: Cloud API and Docker registry password. Required field.
- `cloud_region`: Region where the environment is set up in the Console. Required field.
- `docker_registry_url`: URL to the Docker image registry. Optional field. Defaults to `registry.vuestorefront.cloud`.
- `console_api_url`: URL to the Console. Optional field. Defaults to `https://api.platform.vuestorefront.io`.
- `version`: Docker image tag that will be deployed. Example: 2.3.0, 3.1.0-rc.1. If not passed, github.sha will be used
- `extension_module_name`: Extension module name. It’s used as the name of the docker image and path where the api is available. Default value is `ct-stripe-extension`.
- `extension_module_port`: Port of the extension module. Default value is `8080`.
- `notification_module_name`: Notification module name. It’s used as the name of the docker image and path where the api is available. Default value is `ct-stripe-notification`.
- `notification_module_port`: Port of the notification module. Default value is `8081`.
104 changes: 104 additions & 0 deletions build-stripe-ct/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
name: Build Stripe CT Module
description: Builds Stripe CT module docker image
inputs:
project_name:
description: "Project name"
required: true
docker_registry_url:
description: "Docker registry url"
required: false
default: "registry.vuestorefront.cloud"
cloud_username:
description: "Cloud username"
required: true
cloud_password:
description: "Cloud password"
required: true
version:
description: "Version of the app"
required: false
extension_module_name:
description: "Stripe CT extension module name"
required: false
default: "ct-stripe-extension"
extension_module_port:
description: "Stripe CT extension module port"
required: false
default: "8080"
extension_module_config:
description: "Stripe CT extension module config"
required: true
notification_module_name:
description: "Stripe CT notification module name"
required: false
default: "ct-stripe-notification"
notification_module_port:
description: "Stripe CT notification module port"
required: false
default: "8081"
notification_module_config:
description: "Stripe CT notification module config"
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"
# Extension module
- name: Check for existing docker image (${{ inputs.extension_module_name }})
id: check-existing-image-for-extension
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/${{ inputs.extension_module_name }}
tag: ${{ inputs.version || github.sha }}

- name: Build and publish docker image (${{ inputs.extension_module_name }})
uses: elgohr/Publish-Docker-Github-Action@v5
if: ${{ steps.check-existing-image-for-extension.outputs.exists == 'false' }}
with:
name: ${{ inputs.project_name }}-storefrontcloud-io/${{ inputs.extension_module_name }}:${{ inputs.version || github.sha }}
registry: ${{ inputs.docker_registry_url }}
username: ${{ inputs.cloud_username }}
password: ${{ inputs.cloud_password }}
dockerfile: .vuestorefrontcloud/docker/${{ inputs.extension_module_name }}/Dockerfile
buildoptions: --compress
buildargs: INTEGRATION_CONFIG,INTEGRATION_PORT
env:
INTEGRATION_CONFIG: ${{ inputs.extension_module_config }}
INTEGRATION_PORT: ${{ inputs.extension_module_port }}

# Notification module
- name: Check for existing docker image (${{ inputs.notification_module_name }})
id: check-existing-image-for-notification
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/${{ inputs.notification_module_name }}
tag: ${{ inputs.version || github.sha }}

- name: Build and publish docker image (${{ inputs.notification_module_name }})
uses: elgohr/Publish-Docker-Github-Action@v5
if: ${{ steps.check-existing-image-for-notification.outputs.exists == 'false' }}
with:
name: ${{ inputs.project_name }}-storefrontcloud-io/${{ inputs.notification_module_name }}:${{ inputs.version || github.sha }}
registry: ${{ inputs.docker_registry_url }}
username: ${{ inputs.cloud_username }}
password: ${{ inputs.cloud_password }}
dockerfile: .vuestorefrontcloud/docker/${{ inputs.notification_module_name }}/Dockerfile
buildoptions: --compress
buildargs: INTEGRATION_CONFIG,INTEGRATION_PORT
env:
INTEGRATION_CONFIG: ${{ inputs.notification_module_config }}
INTEGRATION_PORT: ${{ inputs.notification_module_port }}
30 changes: 15 additions & 15 deletions deploy/action.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
name: Deploy Storefront
description: Builds Middleware app docker image
description: Deploy the Storefront to the Console
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:
Expand All @@ -32,7 +32,7 @@ runs:
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
Expand All @@ -50,18 +50,18 @@ runs:
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 }}

- name: Update deployment status (failure)
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 }}
83 changes: 83 additions & 0 deletions deploy/stripe-ct/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
name: Deploy Stripe CT
description: Deploy Storefront with Stripe for Commercetools
inputs:
project_name:
description: "Project name"
required: true
docker_registry_url:
description: "Docker registry url"
required: false
default: "registry.vuestorefront.cloud"
cloud_username:
description: "Cloud username"
required: true
cloud_password:
description: "Cloud password"
required: true
cloud_region:
description: "Cloud region"
required: true
console_api_url:
description: "URI for Vue Storefront Console API"
required: false
default: "https://api.platform.vuestorefront.io"
version:
description: "Version of the app"
required: false
extension_module_name:
description: "Stripe CT extension module name"
required: false
default: "ct-stripe-extension"
extension_module_port:
description: "Stripe CT extension module port"
required: false
default: "8080"
notification_module_name:
description: "Stripe CT notification module name"
required: false
default: "ct-stripe-notification"
notification_module_port:
description: "Stripe CT notification module port"
required: false
default: "8081"

runs:
using: "composite"
steps:
- uses: chrnorm/deployment-action@releases/v2
name: Create GitHub deployment
id: deployment
with:
token: "${{ github.token }}"
environment-url: https://${{ inputs.project_name }}.${{ inputs.cloud_region }}.gcp.storefrontcloud.io
environment: production
initial-status: in_progress

- name: Deploy Storefront + Middleware + Stripe CT modules
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 }}","middlewareData":{"path":"/api/","port":4000,"has_base_path":false},"additionalApps":{"apps":{"commercetools-stripe-extension-module":{"name":"${{ inputs.extension_module_name }}","tag":"${{ inputs.version || github.sha }}","image":"${{ inputs.docker_registry_url }}/${{ inputs.project_name }}-storefrontcloud-io/${{ inputs.extension_module_name }}","path":"/${{ inputs.extension_module_name }}/","port":"${{ inputs.extension_module_port }}","has_base_path":false},"commercetools-stripe-notification-module":{"name":"${{ inputs.notification_module_name }}","tag":"${{ inputs.version || github.sha }}","image":"${{ inputs.docker_registry_url }}/${{ inputs.project_name }}-storefrontcloud-io/${{ inputs.notification_module_name }}","path":"/${{ inputs.notification_module_name }}/","port":"${{ inputs.notification_module_port }}","has_base_path":false}}}}'
timeout: 60000

- name: Update deployment status (success)
if: success()
uses: chrnorm/deployment-status@releases/v2
with:
token: "${{ github.token }}"
environment-url: https://${{ inputs.project_name }}.${{ inputs.cloud_region }}.gcp.storefrontcloud.io
state: "success"
description: Congratulations! The deploy is done.
deployment-id: ${{ steps.deployment.outputs.deployment_id }}

- name: Update deployment status (failure)
if: failure()
uses: chrnorm/deployment-status@releases/v2
with:
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"
deployment-id: ${{ steps.deployment.outputs.deployment_id }}

0 comments on commit b48b7f3

Please sign in to comment.