The 'spare' command makes easily the release of Single Page Applications. Spare constructs the infrastructure on AWS to operate the SPA, and then deploys the SPA (please note that it does not support building the SPA). Developers can inspect the infrastructure as CloudFormation before or after its construction.
The infrastructure for S3 and CloudFront is configured as shown in the diagram when you run the "spare build" command.
When you run "spare deploy," it uploads the SPA (Single Page Application) from the specified directory to S3. The diagram below represents a sample SPA delivered by CloudFront. Please note that the "spare" command does not perform TypeScript compilation or any other build steps. It only handles the deployment of your files to S3.
If you does not have the golang development environment installed on your system, please install golang from the golang official website.
go install github.com/nao1215/spare@latest
init subcommand create the configuration file .spare.yml in the current directory. If you want to change the configuration file name, please use the edit subcommand.
Below is the .spare.yml file created by the 'init' subcommand. As it's currently under development, the parameters will continue to change.
spareTemplateVersion: 0.0.1
deployTarget: src
region: us-east-1
customDomain: ""
s3BucketName: spare-us-east-1-ukdzd41mdfch7e6
allowOrigins: []
debugLocalstackEndpoint: http://localhost:4566
Key | Default Value | Description |
---|---|---|
spareTemplateVersion |
"0.0.1" | The version of the Spare template. Unavailable. |
deployTarget |
src | The path of the deployment target (SPA). |
region |
us-east-1 | The AWS region. |
customDomain |
"" | The domain name for CloudFront. If not specified, the CloudFront default domain name is used. Unavailable. |
s3BucketName |
spare-{REGION}-{RANDOM_ID} | The name of the S3 bucket. |
allowOrigins |
"" | The list of domains allowed to access the SPA. Unavailable. |
debugLocalstackEndpoint |
http://localhost:4566 | The endpoint for debugging Localstack. |
The 'build' subcommand constructs the AWS infrastructure.
$ spare build --debug
2023/09/02 17:28:18 INFO [VALIDATE] check .spare.yml
2023/09/02 17:28:18 INFO [VALIDATE] ok .spare.yml
2023/09/02 17:28:18 INFO [CONFIRM ] check the settings
[debug mode]
true
[aws profile]
localstack
[.spare.yml]
spareTemplateVersion: 0.0.1
deployTarget: testdata
region: ap-northeast-1
customDomain:
s3BucketName: spare-northeast-2q21wk200dunjsem
allowOrigins:
debugLocalstackEndpoint: http://localhost:4566
? want to build AWS infrastructure with the above settings? Yes
2023/09/02 17:28:20 INFO [ CREATE ] start building AWS infrastructure
2023/09/02 17:28:20 INFO [ CREATE ] s3 bucket with public access block policy name=spare-northeast-2q21wk200dunjsem
2023/09/02 17:28:20 INFO [ CREATE ] cloudfront distribution
2023/09/02 17:28:20 INFO [ CREATE ] cloudfront distribution domain=localhost:4516
The 'deploy' subcommand uploads the built artifacts to the S3 bucket.
$ spare deploy --debug
2023/09/02 17:29:01 INFO [ MODE ] debug=true
2023/09/02 17:29:01 INFO [ CONFIG ] profile=localstack
2023/09/02 17:29:01 INFO [ DEPLOY ] target path=testdata bucket name=spare-northeast-2q21wk200dunjsem
2023/09/02 17:29:01 INFO [ DEPLOY ] file name=images/why3.png
2023/09/02 17:29:01 INFO [ DEPLOY ] file name=why.html
2023/09/02 17:29:01 INFO [ DEPLOY ] file name=css/responsive.css
2023/09/02 17:29:01 INFO [ DEPLOY ] file name=about.html
2023/09/02 17:29:01 INFO [ DEPLOY ] file name=css/font-awesome.min.css
2023/09/02 17:29:01 INFO [ DEPLOY ] file name=contact.html
2023/09/02 17:29:01 INFO [ DEPLOY ] file name=js/custom.js
:
: