These are some example files that will be used to teach the DevOps course. There is a small web app and a very simple API.
Tools used:
- VSCode
- Web
- HTML
- CSS
- JavaScript
- python
- flask
- Docker
- AWS
- AWS cli
-
Use VSCode to edit the code and make whatever changes to the source that is required. It is highly suggested that you only change a little before you test the app, like one line at a time if practical.
-
Test locally
- pipenv shell
- pipenv install (Only needed once or when a new package is used)
- py app.py
- In the browser: localhost:5000
- test in browser with this link to localhost:5000!
- note that the hostname should be your computer's name.
-
Build the Docker container locally and test
- In VSCode in the Explorer / Project view; right-click on the file named Dockerfile and select the Build Image... option. A new Image is created on your local machine.
- Start Docker Desktop
- In the Containers / Apps tab, make sure there is no devopstraining container running. If so put your mouse over the Container and select the delete option.
- In the Images tab, there should be a devopstraining image.
- as you move your mouse over the image a RUN option will display. Select it.
- A New Container dialog will display. Select the Optional Settings dropdown.
- In the Ports / Local Host enter 5010. Press Run.
- Test the app running in the container localhost:5010. You can use any available port number instead of 5010.
-
Push changes to the source code repository. The repository is hosted on AWS CodeCommit. ??? Larry add documentation on how to create a repository and push to it. ???
-
Use CodeBuild to test and push a new Docker image to AWS Elastic Container Repository (ECR)
-
To create a CodeBuild project, select CodeBuild from the services dropdown:
- Select Build projects from the left menu
- Select Create build project button
- The Create build project should display
-
Enter MyBuildProject for Project Name
-
Select AWS CodeCommit for Source provider
-
Select devops_training for Repository
-
Select Branch for Reference type
-
Select Main for Branch
-
Select Managed image box for Environment Image
-
Select Ubuntu for Operating system
-
Select Standard for Runtime(s)
-
Select highest number for Image
-
Select Linux for Environment type
-
Click Privileged true
-
Leave New service role for Service role
-
Leave Role name
-
Enter buildspec.yml for Buildspec name
-
Expand Additional configuration
-
Change both Timeouts to 0 Hours and 5 Minutes
-
Enter the following Environment variables
Name Value AWS_ACCOUNT_ID 208019545904 IMAGE_TAG latest IMAGE_REPO_NAME devops Note: Make sure to trim spaces from Names and values.
-
Select Create build project button
-
The project should be created.
-
IMPORTANT: Find the service role that has been defined. It is on the Build details tab of the project.
- Select the Service role link, preferably in a new tab in the browser
- Select the Add policy button
- In the Attach Permissions page search for ecr
- Select the box beside EC2InstanceProfileForImageBuilderECRContainerBuilds and click it on
- Select Attach policy button
-
Now Start the build, as defined in the next step.
-
-
To manually trigger a new build once the Build Project is defined, select CodeBuild from the services dropdown.
- Select Build projects from the left menu
- Select MyBuildProject from the projects
- Select Start build button
- In a few minutes the project should run which will run the tests and create a new docker image with the new version of the software
-
References:
-
-
Automate the build process so that when a commit has been made to the devops repository in CodeCommit the build process is automatically triggered and a new Docker image with the new code is created and pushed to ECR.
-
Select EventBridge Service
-
Select Rules from the menu on the left
- Select Create rule button
- Enter MyBuildDevOpsRule for Name
- Select Event opattern box
- Click Pre-defined pattern by service
- Select AWS from Service provider dropdown
- Select CodeCommit from Service name
- Select CodeCommit Repository State Change from the Event type dropdown
- Click Specific resource(s) by ARN
- Lookup the ARN of your devops CodeCommit repository and enter
- Select CodeBuild project in the Target dropdown
- Lookup the ARN of your CodeBuild project and enter
- Click the Create button
-
References:
-
??? Larry Work Here ???
-
-
Deploy the image on AWS manually
-
Select Amazon Elastic Container Service (ECS)
-
Create a Task
- Select Task definitions from the menu in upper left hand side in the ECS main page
- Select Create new Task Definition button
- Select FARGATE box
- Select Next step button
- The Configure task and container definitions page should display
- Enter MyECSTaskDef in Task Definition Name
- Select the ecsTaskExecutioinRole from the dropdown
- Select .5GB from the dropdown
- Select 0.25vCPU from the dropdown
- Select Add a container
- The Add container page should display
- Enter MyTaskContainer in Container name
- Enter your version of 208019545904.dkr.ecr.ca-central-1.amazonaws.com/devops:latest in Image
- Enter 5000 in port
- Select Add button
- The Configure task and container definitions page should display again
- Select Create
- The Launch Status page should display
- Select View task definition
- Select Task definitions from the menu in upper left hand side in the ECS main page
-
Create a Cluster
- Select Clusters from the menu in upper left hand side in the ECS main page
- Select Create cluster button
- Select Networking only box
- Select Next step button
- The Configure cluster should display
- Enter: MyECSCluster for Cluster name
- Select Create
- Select View Cluster button
- The MyECSCluster should display
- Select Deploy button
- The Deploy page should display
- Select Service box
- Select MyECSTaskDev in the Family dropdown
- Select The Latest in Revision
- Enter MyECSService in Service name
- Spec ---
- Leave Deployment type to Rolling update
- Select Clusters from the menu in upper left hand side in the ECS main page
-
The ?????? Start Here Larry
-
-
Deploy the image on AWS using CloudFormation.
- ??? Needs some work.
- Go to AWS CloudFormation
- Select Create a stack
- Select Options:
- Template is ready
- Upload a template file
- Choose file: devops_training\CloudFormation\createCluster.yaml
- select Next button
- The specify stack details should be displayed.
- Stack name: Stack1
- leave the defaults as is
- SubnetA: (Pick first option on the dropdown)
- SubnetB: (Pick second option on the dropdown)
- VPC (Pick last option on the dropdown )
- select Next button
- The Configure stack options should display.
- leave the defaults as is
- select Next button
- The Review Stack1 should be displayed.
- leave the defaults as is
- At the bottom check true 'I acknowledge that AWS CloudFormation might create IAM resources with custom names.'
- select Create stack button
- this could take a few minutes.
- press the refresh button until the event Stack1 CREATE_COMPLETE shows up at the top of the list.
- Test the application on AWS
- Select the Outputs tab
- Select the Endpoint value/link
- Congragulations. Test the application running on AWS.
-
Deploy an update to a running ECR cluster
- To understand ECR Deploy Concepts with CodeDeploy read this artical.
- This seems like a good step by step???: step by step
There is reference in this artical for:
- information about how to use CodePipeline to detect and automatically deploy changes to an Amazon ECS service with CodeDeploy
- Tutorial: Creating a service using a blue/green deployment
- ??? Larry Finish This
-
Copy the python docker image to your ECR. We do this to avoid docker limits when building and running.
- In ECR create a repository called python.
- Select the repository and push the View push commands
- We modify them slightly to:
- aws ecr get-login-password --region ca-central-1 | docker login --username AWS --password-stdin 208019545904.dkr.ecr.ca-central-1.amazonaws.com
- docker pull python:3.8-slim-buster
- docker tag python:3.8-slim-buster 208019545904.dkr.ecr.ca-central-1.amazonaws.com/python:3.8-slim-buster
- docker push 208019545904.dkr.ecr.ca-central-1.amazonaws.com/python:3.8-slim-buster
-
CloudFormation Info
Questions: * Setting up target groups * Assigning traffic to the target groups
LoadBalancer Listeners Forward to TargetGroups with Rules
A listener is attached to a Service
Info
(How to show/teach the students to do this in 1.5 weeks)
- Automate the build process so the container gets built when new code is checked in.
- Automate the deploy process so the container gets deployed when the container gets built.
- do a simple deploy
- use a blue green deploy strategy
- Run the tests. Determine if the tests can and should be run inside the Docker container?
- Publish test results
Some piece of code in here
Some Stuff
- Point
- Point
Ordered List
- Stuff
- Stuff
- Stuff
- Stuff
- Stuff
- Stuff
It's very easy to make some words bold and other words italic with Markdown. You can even link to Google!
208019545904.dkr.ecr.ca-central-1.amazonaws.com/devops@sha256:03f4fb0fbce187c605046658f734c49bef1131d55c9ebdbcdd53b05b8ee98f45
208019545904.dkr.ecr.ca-central-1.amazonaws.com/devops@sha256:3c6109df11e94cf5cb24a12ff7321dbc813cc577efb350f9055e9c11f5278ad1
docker tag sha256:3c6109df11e94cf5cb24a12ff7321dbc813cc577efb350f9055e9c11f5278ad1 208019545904.dkr.ecr.ca-central-1.amazonaws.com/devops:V10
docker images 208019545904.dkr.ecr.ca-central-1.amazonaws.com/devops
docker images 208019545904.dkr.ecr.ca-central-1.amazonaws.com/devops
docker tag 0e5574283393 myregistryhost:5000/fedora/httpd:version1.0
sha256:03f4fb0fbce187c605046658f734c49bef1131d55c9ebdbcdd53b05b8ee98f45
docker pull 208019545904.dkr.ecr.ca-central-1.amazonaws.com/devops@sha256:03f4fb0fbce187c605046658f734c49bef1131d55c9ebdbcdd53b05b8ee98f45
docker tag 208019545904.dkr.ecr.ca-central-1.amazonaws.com/devops:latest 208019545904.dkr.ecr.ca-central-1.amazonaws.com/devops:v0.11
docker tag 7107d2fbc677 208019545904.dkr.ecr.ca-central-1.amazonaws.com/devops:v0.10
docker push 208019545904.dkr.ecr.ca-central-1.amazonaws.com/devops:v0.10
[Container] 2021/08/10 04:34:56 Running command aws ecr get-login-password --region $AWS_DEFAULT_REGION | docker login --username AWS --password-stdin $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com WARNING! Your password will be stored unencrypted in /root/.docker/config.json. Configure a credential helper to remove this warning. See https://docs.docker.com/engine/reference/commandline/login/#credentials-store
Login Succeeded
[Container] 2021/08/11 03:21:05 Running command aws ecr get-login-password --region $AWS_DEFAULT_REGION | docker login --username AWS --password-stdin $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com Error response from daemon: Get https://.dkr.ecr.ca-central-1.amazonaws.com/v2/: dial tcp: lookup .dkr.ecr.ca-central-1.amazonaws.com: no such host