Skip to content

Commit

Permalink
Update onecfg
Browse files Browse the repository at this point in the history
  • Loading branch information
clebert committed Oct 31, 2023
1 parent 8692f20 commit 945736f
Show file tree
Hide file tree
Showing 49 changed files with 6,050 additions and 5,432 deletions.
1 change: 0 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
"allowDirectConstAssertionInArrowFunctions": true
}
],
"@typescript-eslint/no-duplicate-imports": "error",
"@typescript-eslint/no-floating-promises": "error",
"@typescript-eslint/no-import-type-side-effects": "error",
"@typescript-eslint/no-require-imports": "error",
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ jobs:
CI:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version-file: .node-version
- uses: bahmutov/npm-install@v1
- run: npm run ci
- run: bash ./ci.sh
- env:
NPM_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
if: ${{ github.event_name == 'release' }}
Expand Down
2 changes: 1 addition & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/.prettierrc.json
/LICENSE*
/.eslintrc.json
/.github/workflows/ci.yml
/coverage
/jest.config.json
/package-lock.json
/.github/workflows/ci.yml
/.swcrc
/tsconfig.base.json
/tsconfig.json
Expand Down
2 changes: 1 addition & 1 deletion .prettierrc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"bracketSpacing": false,
"printWidth": 80,
"printWidth": 100,
"proseWrap": "always",
"quoteProps": "consistent",
"singleQuote": true,
Expand Down
6 changes: 5 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
"[json]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[markdown]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
Expand All @@ -29,7 +32,7 @@
},
"editor.formatOnSave": true,
"editor.rulers": [
80
100
],
"files.exclude": {
".editorconfig": true,
Expand All @@ -45,6 +48,7 @@
".vscode": true,
".vscode/extensions.json": true,
".vscode/settings.json": true,
"ci.sh": true,
"jest.config.json": true,
"tsconfig.base.json": true,
"tsconfig.emit.json": true,
Expand Down
55 changes: 21 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@ npm install aws-simple aws-cdk

## Getting started

The following are the steps to deploy a website using `aws-simple` and the AWS
CDK.
The following are the steps to deploy a website using `aws-simple` and the AWS CDK.

### 1. Create a config file

Create a config file named `aws-simple.config.mjs`, which exports a function
that describes a website stack:
Create a config file named `aws-simple.config.mjs`, which exports a function that describes a
website stack:

```js
// @ts-check
Expand All @@ -28,31 +27,28 @@ export default (port) => ({
});
```

The exported function optionally gets a DEV server `port` argument when called
in the context of the `aws-simple start [options]` CLI command.
The exported function optionally gets a DEV server `port` argument when called in the context of the
`aws-simple start [options]` CLI command.

### 2. Create a public hosted zone on AWS Route 53

Create a **public** hosted zone on AWS Route 53 to make a website available
under a particular domain. The required certificate is created automatically by
`aws-simple` during deployment.
Create a **public** hosted zone on AWS Route 53 to make a website available under a particular
domain. The required certificate is created automatically by `aws-simple` during deployment.

### 3. Create an AWS IAM user

Create an AWS IAM user with programmatic access and an
[AWS IAM policy](#aws-iam-policy-example) with sufficient permissions.
Create an AWS IAM user with programmatic access and an [AWS IAM policy](#aws-iam-policy-example)
with sufficient permissions.

### 4. Set the credentials

Set the credentials of the AWS IAM user using the two environment variables,
`AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY`. Alternatively, the credentials
are retrieved using the AWS profile.
Set the credentials of the AWS IAM user using the two environment variables, `AWS_ACCESS_KEY_ID` and
`AWS_SECRET_ACCESS_KEY`. Alternatively, the credentials are retrieved using the AWS profile.

### 5. Set the AWS region

Set the AWS region using either the environment variable `AWS_REGION` or
`AWS_DEFAULT_REGION` evaluated in the specified order. Alternatively, the region
is retrieved using the AWS profile.
Set the AWS region using either the environment variable `AWS_REGION` or `AWS_DEFAULT_REGION`
evaluated in the specified order. Alternatively, the region is retrieved using the AWS profile.

### 6. Bootstrap the AWS environment

Expand Down Expand Up @@ -106,12 +102,11 @@ export default () => ({
});
```

An optional alias record name allows multiple website variants to be deployed
and operated simultaneously. Example: `stage.example.com`, `test.example.com`
An optional alias record name allows multiple website variants to be deployed and operated
simultaneously. Example: `stage.example.com`, `test.example.com`

Except for the specified hosted zone, the website variants do not share any
infrastructure. For the management of multiple website variants, there are the
following two CLI commands:
Except for the specified hosted zone, the website variants do not share any infrastructure. For the
management of multiple website variants, there are the following two CLI commands:

- `aws-simple list [options]`
- `aws-simple purge [options]`
Expand Down Expand Up @@ -426,8 +421,7 @@ node --enable-source-maps $(npm bin)/aws-simple start

### `onSynthesize` hooks

To implement advanced features, `onSynthesize` hooks can be used. Below are two
examples.
To implement advanced features, `onSynthesize` hooks can be used. Below are two examples.

#### Configuring a firewall

Expand Down Expand Up @@ -466,9 +460,7 @@ export default () => ({

onSynthesize: ({stack, restApi, lambdaFunction}) => {
lambdaFunction.role.addManagedPolicy(
aws_iam.ManagedPolicy.fromAwsManagedPolicyName(
`AmazonS3ReadOnlyAccess`,
),
aws_iam.ManagedPolicy.fromAwsManagedPolicyName(`AmazonS3ReadOnlyAccess`),
);
},
},
Expand Down Expand Up @@ -512,8 +504,7 @@ export default () => ({
### `onStart` hook

The `onStart` hook can be used to customize the DEV server's
[Express app](https://expressjs.com/en/5x/api.html#app), e.g. to configure a
proxy middleware:
[Express app](https://expressjs.com/en/5x/api.html#app), e.g. to configure a proxy middleware:

```js
import {createProxyMiddleware} from 'http-proxy-middleware';
Expand Down Expand Up @@ -628,11 +619,7 @@ Note: The `onStart` hook is called before the routes are registered.
{
"Sid": "AwsSimple9",
"Effect": "Allow",
"Action": [
"iam:ListAttachedRolePolicies",
"iam:DetachRolePolicy",
"iam:DeleteRole"
],
"Action": ["iam:ListAttachedRolePolicies", "iam:DetachRolePolicy", "iam:DeleteRole"],
"Resource": "arn:aws:iam::*:role/aws-simple-*"
}
]
Expand Down
6 changes: 6 additions & 0 deletions ci.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
set -e # Terminates script at the first error
set -o pipefail # Sets the exit status for pipes
set -u # Triggers an error when an unset variable is called
set -o noclobber # Prevents from overwriting existing files
npm run ci
24 changes: 21 additions & 3 deletions onecfg.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,33 @@
"https://raw.githubusercontent.com/clebert/onecfg-lib/main/lib/onecfg-editorconfig.json",
"https://raw.githubusercontent.com/clebert/onecfg-lib/main/lib/onecfg-eslint.json",
"https://raw.githubusercontent.com/clebert/onecfg-lib/main/lib/onecfg-git.json",
"https://raw.githubusercontent.com/clebert/onecfg-lib/main/lib/onecfg-github-ci.json",
"https://raw.githubusercontent.com/clebert/onecfg-lib/main/lib/onecfg-github-ci-node.json",
"https://raw.githubusercontent.com/clebert/onecfg-lib/main/lib/onecfg-github-ci-npm.json",
"https://raw.githubusercontent.com/clebert/onecfg-lib/main/lib/onecfg-github-ci-npm-publish.json",
"https://raw.githubusercontent.com/clebert/onecfg-lib/main/lib/onecfg-jest.json",
"https://raw.githubusercontent.com/clebert/onecfg-lib/main/lib/onecfg-node.json",
"https://raw.githubusercontent.com/clebert/onecfg-lib/main/lib/onecfg-node-github.json",
"https://raw.githubusercontent.com/clebert/onecfg-lib/main/lib/onecfg-npm-github.json",
"https://raw.githubusercontent.com/clebert/onecfg-lib/main/lib/onecfg-prettier.json",
"https://raw.githubusercontent.com/clebert/onecfg-lib/main/lib/onecfg-swc.json",
"https://raw.githubusercontent.com/clebert/onecfg-lib/main/lib/onecfg-typescript.json",
"https://raw.githubusercontent.com/clebert/onecfg-lib/main/lib/onecfg-typescript-emit.json",
"https://raw.githubusercontent.com/clebert/onecfg-lib/main/lib/onecfg-typescript-eslint.json",
"https://raw.githubusercontent.com/clebert/onecfg-lib/main/lib/onecfg-vscode.json"
]
],
"patches": {
"ci.sh": [
{
"value": ["npm run ci"]
}
],
"tsconfig.base.json": [
{
"value": {
"compilerOptions": {
"exactOptionalPropertyTypes": false
}
}
}
]
}
}

0 comments on commit 945736f

Please sign in to comment.