acme-serverless-shipment

module
v0.0.0-...-1f60787 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 21, 2020 License: MIT

README

Shipment

A shipping service, because what is a shop without a way to ship your purchases?

The Shipping service is part of the ACME Fitness Serverless Shop. The goal of this specific service is, as the name implies, to ship products using a wide variety of shipping suppliers.

Prerequisites

Deploying

With Pulumi (using SQS for eventing)

To deploy the Shipment Service you'll need a Pulumi account. Once you have your Pulumi account and configured the Pulumi CLI, you can initialize a new stack using the Pulumi templates in the pulumi folder.

cd pulumi
pulumi stack init <your pulumi org>/acmeserverless-shipment/dev

Pulumi is configured using a file called Pulumi.dev.yaml. A sample configuration is available in the Pulumi directory. You can rename Pulumi.dev.yaml.sample to Pulumi.dev.yaml and update the variables accordingly. Alternatively, you can change variables directly in the main.go file in the pulumi directory. The configuration contains:

config:
  aws:region: us-west-2 ## The region you want to deploy to
  awsconfig:generic:
    sentrydsn: ## The DSN to connect to Sentry
    accountid: ## Your AWS Account ID
    wavefronturl: ## The URL of your Wavefront instance
    wavefronttoken: ## Your Wavefront API token
  awsconfig:tags:
    author: retgits ## The author, you...
    feature: acmeserverless
    team: vcs ## The team you're on
    version: 0.1.0 ## The version

To create the Pulumi stack, and create the shipment service, run pulumi up.

If you want to keep track of the resources in Pulumi, you can add tags to your stack as well.

pulumi stack tag set app:name acmeserverless
pulumi stack tag set app:feature acmeserverless-shipment
pulumi stack tag set app:domain shipment
With CloudFormation (using EventBridge for eventing)

Clone this repository

git clone https://github.com/retgits/acme-serverless-shipment
cd acme-serverless-shipment

Get the Go Module dependencies

go get ./...

Change directories to the cloudformation folder

cd ./cloudformation

If your event bus is not called acmeserverless, update the name of the feature parameter in the template.yaml file. Now you can build and deploy the Lambda function:

make build
make deploy

Testing

To test, you can use the SQS or EventBridge test apps in the acme-serverless repo.

Building for Google Cloud Run

If you have Docker installed locally, you can use docker build to create a container which can be used to try out the shipment service locally and for Google Cloud Run.

To build your container image using Docker:

Run the command:

VERSION=`git describe --tags --always --dirty="-dev"`
docker build -f ./cmd/cloudrun-shipment-http/Dockerfile . -t gcr.io/[PROJECT-ID]/shipment:$VERSION

Replace [PROJECT-ID] with your Google Cloud project ID

If you have not yet configured Docker to use the gcloud command-line tool to authenticate requests to Container Registry, do so now using the command:

gcloud auth configure-docker

You need to do this before you can push or pull images using Docker. You only need to do it once.

Push the container image to Container Registry:

docker push gcr.io/[PROJECT-ID]/shipment:$VERSION

The container relies on the environment variables:

  • SENTRY_DSN: The DSN to connect to Sentry
  • K_SERVICE: The name of the service (in Google Cloud Run this variable is automatically set, defaults to shipment if not set)
  • VERSION: The version you're running (will default to dev if not set)
  • PORT: The port number the service will listen on (will default to 8080 if not set)
  • STAGE: The environment in which you're running
  • WAVEFRONT_TOKEN: The token to connect to Wavefront
  • WAVEFRONT_URL: The URL to connect to Wavefront (will default to debug if not set)

A docker run, with all options, is:

docker run --rm -it -p 8080:8080 -e SENTRY_DSN=abcd -e K_SERVICE=shipment \
  -e VERSION=$VERSION -e PORT=8080 -e STAGE=dev -e WAVEFRONT_URL=https://my-url.wavefront.com \
  -e WAVEFRONT_TOKEN=efgh -e gcr.io/[PROJECT-ID]/shipment:$VERSION

Replace [PROJECT-ID] with your Google Cloud project ID

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

See the LICENSE file in the repository

Directories

Path Synopsis
cmd
lambda-shipment-eventbridge
Package main is a shipment service, because what is a shop without a way to ship your purchases? The Shipping service is part of the [ACME Fitness Serverless Shop](https://github.com/retgits/acme-serverless).
Package main is a shipment service, because what is a shop without a way to ship your purchases? The Shipping service is part of the [ACME Fitness Serverless Shop](https://github.com/retgits/acme-serverless).
lambda-shipment-sqs
Package main is a shipment service, because what is a shop without a way to ship your purchases? The Shipping service is part of the [ACME Fitness Serverless Shop](https://github.com/retgits/acme-serverless).
Package main is a shipment service, because what is a shop without a way to ship your purchases? The Shipping service is part of the [ACME Fitness Serverless Shop](https://github.com/retgits/acme-serverless).
internal
emitter
Package emitter contains the interfaces that the Shipment service in the ACME Serverless Fitness Shop needs to send events to other services.
Package emitter contains the interfaces that the Shipment service in the ACME Serverless Fitness Shop needs to send events to other services.
emitter/eventbridge
Package eventbridge uses Amazon EventBridge as a serverless event bus that makes it easy to connect applications together using data from your own applications, integrated Software-as-a-Service (SaaS) applications, and Serverless Fitness Shops.
Package eventbridge uses Amazon EventBridge as a serverless event bus that makes it easy to connect applications together using data from your own applications, integrated Software-as-a-Service (SaaS) applications, and Serverless Fitness Shops.
emitter/mock
Package mock uses the log file to log all incoming events.
Package mock uses the log file to log all incoming events.
emitter/sqs
Package sqs uses Amazon Simple Queue Service (SQS) as a fully managed message queuing service that enables you to decouple and scale microservices, distributed systems, and serverless fitness shops.
Package sqs uses Amazon Simple Queue Service (SQS) as a fully managed message queuing service that enables you to decouple and scale microservices, distributed systems, and serverless fitness shops.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL