Skip to content

Commit

Permalink
Initial commit; copy from repo TRC-AWS-4-B
Browse files Browse the repository at this point in the history
  • Loading branch information
sgalushin committed Jun 30, 2021
0 parents commit e02cfc0
Show file tree
Hide file tree
Showing 100 changed files with 39,435 additions and 0 deletions.
80 changes: 80 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
### Node template
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)
web_modules/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
.env.test


# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*

### IDE
.idea

### AWS CloudFormation & SAM
.aws-sam
samconfig.toml
template-export.yaml

### MacOS
.DS_Store

### Specific to project
# Build dir
build
dist
21 changes: 21 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 Sergei Galushin

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
58 changes: 58 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
ifndef STAGE
$(error STAGE is not set)
endif
ifndef REGION
$(error REGION is not set)
endif
ifndef INTEGRATION_API_KEY
$(error INTEGRATION_API_KEY is not set)
endif
ifndef BUCKET_FOR_LAMBDAS
$(error BUCKET_FOR_LAMBDAS is not set)
endif

export

target:
$(info ${HELP_MESSAGE})
@exit 0

deploy:

$(info [*] Deploying...)
$(MAKE) deploy.backend-shared
$(MAKE) deploy.integration-endpoint
$(MAKE) deploy.product-catalog
$(MAKE) deploy.rolls


deploy.backend-shared:
$(MAKE) -C backend-shared deploy

deploy.integration-endpoint:
$(MAKE) -C integration-endpoint deploy

deploy.product-catalog:
$(MAKE) -C product-catalog deploy

deploy.rolls:
$(MAKE) -C rolls deploy

define HELP_MESSAGE

Environment variables:

These variables are automatically filled at CI time except STRIPE_SECRET_KEY
If doing a dirty/individual/non-ci deployment locally you'd need them to be set

STAGE: "dev"
Description: Feature branch name used as part of stacks name; added by Amplify Console by default
REGION: "eu-west-1"
Description: AWS Region, where the stack will be deployed
INTEGRATION_API_KEY: "t4b4e2egamkio8s3n0u6"
Description: An API Key, a string of minimum 20 characters.
This key will be used as an authentification of a ERP Master Data system to send events to TRC integration endpoint.
It must be included in all requests from a ERP system in the 'x-api-key' header.

Common usage:
endef
93 changes: 93 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# TRC (Textile Rolls Controller)

A textile factory floor management software for tracking fabricated rolls after they are released from finishing (dying) department. **TRC** features:

- [x] roll registration
- [x] roll cutting
- [x] quality control data input
- [x] label creation

Not yet implemented:

- [ ] roll packaging
- [ ] rolls order fulfillment
- [ ] consolidated transfer of produced rolls to ERP

**TRC** must be integrated with existing ERP system, which servers as a Master Data Management system. ERP sends events to TRC, describing updates to products and characteristics. TRC uses this events to rebuild a read-only copy of a product catalog. Integration with `1C:Enterprise ERP 2.4` is implemented, but the implementation is currently not open-sourced.

**TRC** is a serverless app, intended to run only on AWS cloud. It uses SQS, Cognito, DynamoDB, S3 and other AWS services.

## Demo

View animated gifs - [demo](./docs/demo.md), demonstrating main functionality (warning - huge gifs - traffic!)

## Components

| Component | Desrciption |
|-----------------|---|
| [Shared Components](./backend-shared) | AWS infrastructure that is used by more than one service: User pool, shared S3 buckets etc. |
| [Integration Endpoint](./integration-endpoint) | Provides an HTTP endpoint for ERP to send events, describing updates in products. ERP is authenticated via an API key. |
| [Product Catalog](./product-catalog) | Stores products and product characteristics (descriptions and pictures). |
| [Rolls](./rolls) | Core component of TRC: provides mechanisms for creation, modification and retrieval of various types of rolls: original, modified, descendant (cut up). |
| [Frontend](https://github.com/sgalushin/textile-rolls-controller-frontend) | Web interface (a separate repo). |

### Components Overview

![Components schema](docs/components-schema.png)

## Getting Started & Deployment

### Requirements

* Node 14
* [SAM CLI](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html)
* [GNU Make](https://www.gnu.org/software/make/)
* [Docker](https://docs.docker.com/install/) (for running service tests with DynamoDB Local)

### Deployment of the whole TRC project

1. [Deploy the backend](#backend-deployment) (this project).

2. Update the 1C:ERP instance with TRC integration patches. Create a new Integration endpoint with the following parameters:
- `URL` is a value of an output `APIAddress` from `TRC-${STAGE}-integration-endpoint` stack.
- `Key` is `INTEGRATION_API_KEY` that was specified at step 1.

3. Deploy the frontend. Make sure that during the build process all necessary environment variables exist - see `README.md` in the frontend project.

4. Log in into AWS Console, go to Cognito, select corresponding User Pool and create the first user (by default in all project's CloudFormation templates user registration is disabled for security reasons). Try to log in into web interface using these credentials.

5. To perform an initial population of a TRC Product Catalog, in the 1C:ERP instance execute "save in batch" command for all necessary products and their corresponding characteristics; this will put them into an upload queue. Set up a scheduled upload to the TRC endpoint (set up at step 2) or trigger a manual upload.

### Backend deployment

1. Manually create an S3 bucket (or use an existing one). This bucket will be used as `BUCKET_FOR_LAMBDAS` during deployment.

2. (optional) By default CORS policy is `Allow-Origin: "*"`. You can tighten CORS restrictions in the Product Catalog and Rolls services:
- Change the `Api/Properties/Cors/AllowOrigin/` section in each `template.yaml`.
- Change `SERVICE_DIRECTORY/src/lambda-handlers/accessControlHeaders.json`

3. From the root project directory run the following command:

`make deploy PARAMETERS`

| Parameter | Example | Description |
|---|---|---|
| STAGE | dev | An identifier of a specific instance of an app. Might match a git branch. |
| INTEGRATION_API_KEY | wcqp4peshv57dulfakpm | An API key that will be used to authenticate 1C:ERP instance, sending events to the Integration Endpoint. Must be a string, minimum 20 characters. |
| REGION | eu-west-1 | AWS region
| BUCKET_FOR_LAMBDAS | my-bucket-for-lambdas-0492320 | An S3 bucket, located in the `REGION` region. `sam package` command, defined in the `Makefile`, will put lambda's source code in this bucket.

Example: `make deploy STAGE=st2 INTEGRATION_API_KEY=wcqp4peshv57dulfakpm REGION=eu-west-1 BUCKET_FOR_LAMBDAS=my-bucket-for-lambdas-0492320`

Keep in mind that when deploying a new stage, integration API key must not be reused from another stages. Thus, there must not be more than one stage with the same integration key.

After initial deployment specific services can be updated with `make deploy.SERVICE` command, for example
`make deploy.rolls STAGE=st2 INTEGRATION_API_KEY=wcqp4peshv57dulfakpm REGION=eu-west-1 BUCKET_FOR_LAMBDAS=my-bucket-for-lambdas-0492320`

## Project status

This app was created as a pre-sales proof-of-concept for a specific client to demonstrate the feasibility of moving some parts of the existing classic three-tier ERP application to a serverless AWS stack. Currently, its development is abandoned.

## License

This project is licensed under the terms of the MIT license. See the [LICENSE](./LICENSE.txt) file.
3 changes: 3 additions & 0 deletions backend-shared/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
deploy:
sam build
sam deploy --no-fail-on-empty-changeset --stack-name trc-$(STAGE)-common --no-confirm-changeset --parameter-overrides "ParameterKey=Stage,ParameterValue=$(STAGE)" --region $(REGION) --resolve-s3 --capabilities CAPABILITY_IAM
1 change: 1 addition & 0 deletions backend-shared/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This service contains only shared (with other services) AWS components, described in `template.yaml`. There is no JS/TS code.
Loading

0 comments on commit e02cfc0

Please sign in to comment.