In this demo you'll learn how to deploy applications to EKS on AWS using Docker Application Templates and GitHub Actions.
This is what you'll be doing:
-
create a GitHub repository to store your demo code and the credentials to deploy to AWS
-
run a Docker Application Template which generates code and a CI/CD pipelie for the .NET Core demo app eShopOnWeb
-
push your local code to GitHub which runs a workflow to create an AWS SQL Server database and an AWS Kubernetes cluster
-
run the app locally in Docker containers to see how it works, and make some simple changes
-
push the changed code to GitHub which runs a workflow to build Docker images, push them to Docker Hub, and deploy the app onto your EKS cluster.
It sounds like a lot, but it's really simple because the template generates documentation for you which guides you through all the steps.
You'll need a few things before you start:
- A version of Docker Desktop with Application Templates enabled.
The demo is a Linux app, so on Windows you need to use Linux container mode. That's the default so you only need to change it if you've switched to Windows container mode.
-
A Docker Hub account, so the pipeline can push the Docker images it builds, and the Kubernetes cluster can pull them.
-
Some tools to work with the source code - Git and Visual Studio Code. If you have Chocolatey set up you can install them with:
choco install -y git
choco install -y visualstudiocode
- AWS access key
Make a note of the output, you'll need to add the details to GitHub
- A GitHub repo. The pipeline runs using GitHub Actions. Create an empty repo and set the following secrets (under Settings...Secrets):
AWS_ACCESS_KEY_ID
- the access key ID for AWSAWS_SECRET_ACCESS_KEY
- the secret key for AWSRDS_SQL_DATABASE_NAME
- the name of the SQL Server database to createRDS_SQL_PASSWORD
- the password for themaster
SQL Server userDOCKER_HUB_USERNAME
- Docker Hub usernameDOCKER_HUB_ACCESS_TOKEN
- Docker Hub Personal Access Token
Update your App Template config in ~/.docker/application-template/preferences.yaml
to include the template library at https://raw.githubusercontent.com/sixeyed/eshoponaws/master/eshoponaws.yaml
.
This example includes the local demo libraries and the main Docker library:
apiVersion: v1alpha1
disableFeedback: false
kind: Preferences
repositories:
- name: eshoponaws
url: https://raw.githubusercontent.com/sixeyed/eshoponaws/master/eshoponaws.yaml
- name: library
url: https://docker-application-template.s3.amazonaws.com/production/v0.1.7/library.yaml
Right-click the Docker whale icon in your taskbar and select Design new application... A window launches asking if you want to choose an existing template or design a custom app; select Choose a template.
If you're running Docker Desktop on Windows you'll be asked if you want to run a Linux or Windows app - the template we'll be using is Linux so select Linux.
Now select the eShop on Web template from the gallery:
From here you'll need to add some details about the deployment, which the template captures as parameters:
-
GitHub Username and Repository name - use the repo you created earlier with all the secrets stored for AWS and Docker Hub
-
AWS region - region to deploy the EKS cluster & RDS database
-
EKS Cluster name - any name for the cluster to create
The other parameters have default values, and you can leave them as they are or change them to suit your deployment.
The SQL Server password is only used when you run the app locally, the AWS deployment uses the password you stored in the GitHub secret
Now click Continue, give your application a name and click Scaffold. Docker Desktop runs the template and generates the source code and GitHub workflows on you local machine.
When the scaffolding process finishes click Run application. That builds and runs the app in local containers. While it's building click Open in Visual Studio Code to launch a VS Code instance with the generated application code:
Now you can follow the generated documentation from the source code. Browse to the README file in the eshop-web
folder and contine from there.
Good luck :)