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.
- Go (at least Go 1.12)
- An AWS account
- A Pulumi account
- A Sentry.io account if you want to enable tracing and error reporting
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
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
To test, you can use the SQS or EventBridge test apps in the acme-serverless repo.
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
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.
See the LICENSE file in the repository