Skip to content

Commit

Permalink
Merge pull request #228 from aligent/feature/MICRO-26_rework-match-ne…
Browse files Browse the repository at this point in the history
…w-architecture

MICRO-26: Rework to match new architecture
  • Loading branch information
kai-nguyen-aligent authored Nov 13, 2023
2 parents fb0b32d + b50598c commit 12d9fc7
Show file tree
Hide file tree
Showing 19 changed files with 8,787 additions and 9,916 deletions.
16 changes: 16 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
root = true

[*]
charset = utf-8
end_of_line = lf
indent_size = 4
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

[{package.json,*.yml,*.md}]
indent_size = 2
indent_style = space

[*.md]
trim_trailing_whitespace = false
4 changes: 4 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
dist
jest.config.js
vite.config.ts
18 changes: 18 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": ["./tsconfig.json"]
},
"plugins": ["@typescript-eslint"],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"prettier"
],
"rules": {
"no-return-await": "off",
"@typescript-eslint/return-await": "error"
}
}
20 changes: 10 additions & 10 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.event.release.target_commitish }}
- name: Use Node.js 16
uses: actions/setup-node@v1
with:
node-version: 16
registry-url: https://registry.npmjs.org/
- run: npm ci
- run: npm run build
- uses: actions/checkout@v2
with:
ref: ${{ github.event.release.target_commitish }}
- name: Use Node.js 18
uses: actions/setup-node@v1
with:
node-version: 18
registry-url: https://registry.npmjs.org/
- run: npm ci
- run: npm run build
38 changes: 19 additions & 19 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@ jobs:
build-and-publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.event.release.target_commitish }}
- name: Use Node.js 16
uses: actions/setup-node@v1
with:
node-version: 16
registry-url: https://registry.npmjs.org/
- run: npm ci
- run: git config --global user.name "Automated NPM Release"
- run: git config --global user.email "[email protected]"
- run: npm version ${{ github.event.release.tag_name }} --allow-same-version
- run: npm run build
- run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- run: git push
env:
github-token: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/checkout@v2
with:
ref: ${{ github.event.release.target_commitish }}
- name: Use Node.js 18
uses: actions/setup-node@v1
with:
node-version: 18
registry-url: https://registry.npmjs.org/
- run: npm ci
- run: git config --global user.name "Automated NPM Release"
- run: git config --global user.email "[email protected]"
- run: npm version ${{ github.event.release.tag_name }} --allow-same-version
- run: npm run build
- run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- run: git push
env:
github-token: ${{ secrets.GITHUB_TOKEN }}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ jspm_packages
# Serverless directories
.serverless

# ESBuild directories
# Build artifacts
.build
*.js
*.map
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
engine-strict=true
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
16
v18.16
4 changes: 4 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Ignore artifacts:
.esbuild
.serverless
package-lock.json
2 changes: 2 additions & 0 deletions .prettierrc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
singleQuote: true
semi: true
48 changes: 24 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
# Serverless Magento

A [Serverless framework](https://www.serverless.com) plugin for handling the registration of a Serverless application with the [magento2-microservice-config](https://bitbucket.org/aligent/magento2-microservice-config) module.
A [Serverless framework](https://www.serverless.com) plugin for handling the registration of a microservices with the [magento2-microservice-config](https://bitbucket.org/aligent/magento2-microservice-config) module.

## Why?

Serverless applications registered with the [magento2-microservice-config](https://bitbucket.org/aligent/magento2-microservice-config) module will have a [Magento authentication token](https://devdocs.magento.com/guides/v2.4/get-started/authentication/gs-authentication-token.html) made available via [AWS SSM](https://docs.aws.amazon.com/systems-manager/latest/userguide/ssm-agent.html). This removes the need to manually create Magento integrations / access tokens for each Serverless application. The registration also provides the opportunity to create an "admin" interface within the Magento admin interface which can be used for managing the serverless application.
Microservices registered with the [magento2-microservice-config](https://bitbucket.org/aligent/magento2-microservice-config) module will have a [Magento authentication token](https://devdocs.magento.com/guides/v2.4/get-started/authentication/gs-authentication-token.html) made available via [AWS SSM](https://docs.aws.amazon.com/systems-manager/latest/userguide/ssm-agent.html). This removes the need to manually create Magento integrations / access tokens for each service. The registration also provides the opportunity to create an "admin" interface within the Magento admin interface which can be used for managing the serverless application.

## Admin Interface
The admin interface is provided as a link to an externally hosed web application which is rendered in the Magento admin interface as an `iframe`. Authorisation context will be injected into the iframe when loaded.

## Deployment
The registration happens as part of the Serverless deploy. If for any reason the registration is not able to take place, the deployment will fail (before any change set has been deployed).

The Serverless plugin will initially register with the [magento2-microservice-config](https://bitbucket.org/aligent/magento2-microservice-config) REST API. At this state the service is "registered" but not "active". A service does not become "active" until an admin user approves it.
The admin interface is provided as a link to an externally hosed web application which is rendered in the Magento admin interface as an `iframe`. Authorisation context will be injected into the iframe when loaded.

An "activator" Lambda function will be deployed along with the Serverless application which repeatedly checks if the service has been "activated" within Magento. Once this is done, any provided admin interface is created and the Magento access token is retrieved and stored within SSM for use by the application.

![serverless output](/images/serverless_output.png)
## Deployment

The Serverless plugin will initially register with the [magento2-microservice-config](https://bitbucket.org/aligent/magento2-microservice-config) REST API. At this state the service is "registered" but not "active". A service does not become "active" until an admin user approves it.

## Serverless configuration

The plugin is configured within the `serverless.yaml` by providing configuration values.

### Example
```
### Example

```yaml
custom:
magento:
baseUrl: 'http://localhost'
name: 'Test Service'
adminInterfaces:
- name: 'Configuration'
app_url: 'https://example.com'
serviceRegistration:
magentoUrl: https://magento.domain.name
magentoApiToken: ${ssm:/magento/api/access-token-for-registration}
displayName: Service name that appears in Magento Admin
description: Short description about the service
appUrl: https://web-app-url.on.cloudfront
permissions:
- Magento_Backend::all
```
### Variables
| Variable | Usage |
| --------------------- | ----------------------------------------------------------- |
| baseUrl | The base URL - including scheme - of the Magento instance.|
| name | The friendly name of the service.|
| adminInterfaces | An array of {name, app_url} representing the admin interfaces to be exposed by Magento|

| Variable | Usage |
| ----------- | --------------------------------------------------------------------------------------- |
| magentoUrl | The base URL - including scheme - of the Magento instance. |
| displayName | The name of the application/service. |
| description | Short description about the application/service. |
| appUrl | The url to access webapp (Only applicable for webapp, other service does not need this) |
| permission | Array of Magento permission. Webapp does not need this |
Binary file removed images/serverless_output.png
Binary file not shown.
Loading

0 comments on commit 12d9fc7

Please sign in to comment.