This project features a python web application utilizing flask framework. Docker was used for containerization. Alpine linux was used for the operating system. Bash was used for scripts. The code pipeline leverages IAM, s3, CodePipeline, CodeCommit, CodeBuild, and ECR. CloudFormation was used for infrastructure as code. Route 53 is handling DNS. EC2 and associated services were used to host the kubernetes environment. Cloud9 was used as the IDE.
The code in this repo offers 2 ways for deploying the application:
- Option 1: Local docker
- Option 2: CodePipeline to kubernetes
This will build the docker image and run it locally on your machine.
-
Clone this github repo.
git clone https://github.com/tommygarvin/tomster.git
-
Build the docker image.
docker build -t tomster:001 ./tomster/build/
-
Run the docker image. Expose port 5000.
docker run -d -p 5000:5000 tomster:001
-
GET messagelist
curl 127.0.0.1:5000/api/v1/messagelist
-
GET messages/message1
curl 127.0.0.1:5000/api/v1/messages/message1
-
Stop 'tomster' containers
docker ps -a | awk '/tomster/ {print $1}' | xargs docker stop
-
Remove unused resources
docker system prune
-
Remove 'tomster' images
docker images | awk '/tomster/ {print $3}' | xargs docker rmi
This will deploy an AWS CodePipeline that builds and deploys the application to a kubernetes cluster of your choosing. I recommend kops https://github.com/kubernetes/kops if you need a kubernetes environment.
View in CloudFormation Designer
-
Deploy the AWS CodePipeline stack via CloudFormation:
-
Copy the contents of this GitHub repo into the CodeCommit repo.
-
Create a new AWS Route 53 alias record for the url you wish to use. Set the alias to your kubernetes ingress controller. Reference ./deploy/aws-r53.json for example.
-
Update ./deploy/k8s-ing.yml with your url.
-
Update ./deploy/config with your kubectl config.
-
Git add, commit, and push the files to the CodeCommit repo.
-
Browse to AWS CodePipeline. Hit 'release change'. Wait for the pipeline to complete.
-
GET messagelist
curl tomster.tommygarvin.com/api/v1/messagelist
-
GET messages/message1
curl tomster.tommygarvin.com/api/v1/messages/message1
- Delete AWS CloudFormation stack.
- Delete AWS Route 53 alias record.
- Delete k8s namespace 'tomster'
GET - Returns all messages
POST - Add a new message
GET - Returns the specified message
DELETE - Delete the specified message
PUT - Updates the specified message
http://tomster.tommygarvin.com/api
http://tomster.tommygarvin.com/api/v1/messagelist
http://tomster.tommygarvin.com/api/v1/messages/message1