Skip to content

retgits/acme-serverless-payment

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

60 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Payment

A payment service, because nothing in life is really free...

The Payment service is part of the ACME Fitness Serverless Shop. The goal of this specific service is to validate credit card payments. Currently the only validation performed is whether the card is acceptable.

Prerequisites

Deploying

With Pulumi (using SQS for eventing)

To deploy the Payment 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-payment/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.2.0 ## The version

To create the Pulumi stack, and create the Payment 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-payment
pulumi stack tag set app:domain payment

With CloudFormation (using EventBridge for eventing)

Clone this repository

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

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 payment 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-payment-http/Dockerfile . -t gcr.io/[PROJECT-ID]/payment:$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]/payment:$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 payment 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=payment \
  -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]/payment:$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

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages