-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37 from andrewnoble94/3musketeers
3musketeers scenarios.
- Loading branch information
Showing
41 changed files
with
668 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"title": "3musketeers", | ||
"description": "Scenarios to introduce the 3musketeers patterns", | ||
"courses": [ | ||
{ | ||
"course_id": "3musketeers-intro", | ||
"title": "3musketeers-intro", | ||
"description": "An Intro to the 3musketeers patternss" | ||
}, | ||
{ | ||
"course_id": "make-docker-compose-env-variables", | ||
"title": "make-docker-compose-env-variabless", | ||
"description": "Makefile Docker Compose Env Varss" | ||
}, | ||
{ | ||
"course_id": "convert-python-to-3musketeers", | ||
"title": "convert-python-to-3musketeers", | ||
"description": "Taking a single python file and implement the 3musketeers patterns" | ||
}, | ||
{ | ||
"course_id": "java-to-3musketeers", | ||
"title": "java-to-3musketeers", | ||
"description": "Starting out with a gradle spring boot application and implementing 3muskteers patterns" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
|
||
## Final Notes | ||
* The drive for the 3 Musketeer the approach is to have a consistent test, build, and deployment pattern for applications. | ||
* Implementation of 3 Musketeers can vary based on the needs of the team. | ||
* The goal is consistency. | ||
|
||
**Pro-Tip - You do not have to use all 3 of the musketeers to be successful, the whole point behind it is a uniformed development experience.** | ||
|
||
This concludes the intro course to the 3musketeers conventions. Stay tuned for more scenarios! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{ | ||
"title": "3musketeers-intro", | ||
"description": "An Intro to the 3musketeers patterns", | ||
"difficulty": "Beginner", | ||
"time": "10", | ||
"details": { | ||
"steps": [ | ||
{ | ||
"title": "Step 1", | ||
"text": "step1.md" | ||
}, | ||
{ | ||
"title": "Step 2", | ||
"text": "step2.md" | ||
}, | ||
{ | ||
"title": "Step 3", | ||
"text": "step3.md" | ||
} | ||
], | ||
"intro": { | ||
"text": "intro.md" | ||
}, | ||
"finish": { | ||
"text": "finish.md" | ||
} | ||
}, | ||
"environment": { | ||
"uilayout": "editor-terminal" | ||
}, | ||
"backend": { | ||
"imageid": "docker" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
Test, build, and deploy your apps from anywhere, the same way. This katacoda will walk you through an introduction to the 3Musketeers practices. 3Musketeers is made up of 3 technologies. They are make, docker and docker-compose. The 3 main pillars of it are Consistency, Control and Confidence. | ||
|
||
## Consistency | ||
Run the same commands no matter where you are | ||
|
||
## Control | ||
Take control of languages, versions, and tools you need, and version source control your pipelines with your preferred VCS like GitHub and GitLab | ||
|
||
## Confidence | ||
Test your code and pipelines locally before your CI/CD tool runs it. Feel confident that if it works locally, it will work in your CI/CD server |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
Musketeer 1 - Make | ||
Make is a build automation tool that automatically builds programs and runs commands via the same interface. Make is installed on all distros of Unix/Linux operating systems. It is also available on Windows operating systems. Make obtains all its knowledge of how to build the program from a file called the ```Makefile```. This file contains ```targets``` that can be executed. | ||
|
||
## Task | ||
Lets create a Makefile in the editor or by clicking the test below and add a target. | ||
`touch Makefile`{{execute}} | ||
|
||
## Task | ||
Lets create our first target inside the Makefile. This will be a simple target that prints ```Hello World``` to the screen. Add the following lines to the Makefile we just created: | ||
|
||
``` | ||
echo: | ||
echo "Hello World" | ||
``` | ||
* TIP: Make doesn't like spaces. Make sure you tab the ```echo "Hello World"``` line | ||
|
||
|
||
## Task | ||
Our next step is to call the make target we just just created. Either type ```make echo``` in the terminal or click the following: | ||
`make echo`{{execute}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
Musketeer 2 - Docker | ||
Docker is a tool designed to make it easier to create, deploy, and run applications by using containers. We can stack up different docker commands into make targets and orchestrate those different steps to help us achieve our desired outcome. In this section we will cover running a docker container from a make target with a simple Hello World example. | ||
|
||
## Task | ||
Lets update our Makefile recipe to call docker run. We will pull and run a simple alpine image and pass it the command echo 'Hello World' | ||
Our echo target should now look like the following snippet: | ||
``` | ||
echo: | ||
docker run --rm alpine echo 'Hello, World!' | ||
``` | ||
In this command, we're telling `docker` to start a container based on the `alpine` image. The docker run command is simultaneously pulling the official `alpine` image from Docker Hub and running the `echo 'Hello, World!'` command inside that container. The remove (`--rm`) flag removes the container when it is finished. Alpine is a very slim Linux distribution. | ||
|
||
## Task | ||
Finally, lets run make echo again and see our results. Either type ```make echo``` in the terminal or click the following: | ||
`make echo`{{execute}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
Musketeer 3 - Docker-Compose | ||
Compose is a tool for defining and running multi-container Docker applications. With Compose, you use a YAML file to configure your application’s services. Then, with a single command, you create and start all the services (and their dependencies) from your configuration. In 3 Musketeers, it also simplifies our Makefiles. | ||
|
||
## Task | ||
Lets update our project to use docker-compose. First thing we need to do is to add a docker-compose.yml file. Lets create a docker-compose.yml file in the editor or by clicking the text below. | ||
`touch docker-compose.yml`{{execute}} | ||
|
||
## Task | ||
The next thing we must do is to load up our docker-compose.yml file. Lets keep it simple and add 1 service. Lets add a service of 'alpine' that pulls down the alpine image. Add the following code to the docker-compose.yml file. | ||
``` | ||
version: '3' | ||
services: | ||
alpine: | ||
image: alpine | ||
``` | ||
|
||
## Task | ||
Next up, we have to update our Makefile recipe to call docker-compose instead of docker. Open up the Makefile and update the recipe to the following: | ||
``` | ||
echo: | ||
docker-compose run --rm alpine echo 'Hello, World!' | ||
``` | ||
|
||
## Task | ||
Finally, let's run our make target. Either type ```make echo``` in the terminal or click the following: | ||
`make echo`{{execute}} | ||
|
||
This was a super simple example of compose, but it is very powerful, to learn more about compose, follow this link https://docs.docker.com/compose/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
FROM python:3-slim |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
help: | ||
@fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/##//' | ||
|
||
build: ## build target will build our containers based on the docker-compose file. | ||
|
||
|
||
up: ## up will build and run our container based on the docker-compose file | ||
|
7 changes: 7 additions & 0 deletions
7
3musketeers/convert-python-to-3musketeers/assets/docker-compose.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
version: '3' | ||
services: | ||
printvars: | ||
build: . | ||
image: printvars-compose:latest | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import os | ||
|
||
breed = os.getenv('DOG_BREED') | ||
|
||
print('The breed of the dog is: %s' % breed) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
## Final Notes | ||
* The drive for the 3 Musketeer the approach is to have a consistent test, build, and deployment pattern for applications. | ||
* Implementation of 3 Musketeers can vary based on the needs of the team. | ||
* The goal is consistency. | ||
|
||
**Pro-Tip - You do not have to use all 3 of the musketeers to be successfull, the whole point behind it is a uniformed development experience.** | ||
|
||
This concludes the python to 3musketeers course. Stay tuned for more scenarios! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
{ | ||
"noindex": true, | ||
"title": "convert-python-to-3musketeers", | ||
"description": "Taking a single python file and implement the 3musketeers patterns", | ||
"difficulty": "Intermediate", | ||
"time": "15", | ||
"details": { | ||
"assets": { | ||
"client": | ||
[ | ||
{ | ||
"file": "printvar.py", | ||
"target": "~/" | ||
}, | ||
{ | ||
"file": "Dockerfile", | ||
"target": "~/" | ||
}, | ||
{ | ||
"file": "docker-compose.yml", | ||
"target": "~/" | ||
}, | ||
{ | ||
"file": "Makefile", | ||
"target": "~/" | ||
} | ||
] | ||
}, | ||
|
||
"steps": [ | ||
{ | ||
"title": "Step 1 Review Python Script", | ||
"text": "step1.md" | ||
|
||
}, | ||
{ | ||
"title": "Step 2 Dockerize", | ||
"text": "step2.md", | ||
"answer": "step2-answer.md" | ||
}, | ||
{ | ||
"title": "Step 3 Docker-Compose", | ||
"text": "step3.md", | ||
"answer": "step3-answer.md" | ||
}, | ||
{ | ||
"title": "Step 4 Makefile", | ||
"text": "step4.md", | ||
"answer": "step4-answer.md" | ||
|
||
} | ||
], | ||
"intro": { | ||
"text": "intro.md" | ||
|
||
}, | ||
"finish": { | ||
"text": "finish.md" | ||
} | ||
}, | ||
"environment": { | ||
"uilayout": "editor-terminal", | ||
"uieditorpath": "/root", | ||
"hideHiddenFiles": "true" | ||
}, | ||
"backend": { | ||
"imageid": "ubuntu1904" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Welcome! In today's course, we will be working through taking a single python script and converting it to use the 3musketeers patterns. In this scenario, we will cover the following topics: | ||
1. Review the python script | ||
2. Convert Script to use Docker | ||
3. Implement Docker-Compose | ||
4. Implement a Makefile to run the script via docker-compose | ||
|
||
For more in depth information on the 3musketeers patterns visit their website at https://3musketeers.io/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
Lets review the python script `printvar.py`{{open}}. It is a simple python script that prints some text to stdout. | ||
In line 1, we import the os package. Next, we create a variable called 'breed' and set it to the value of the environment variable DOG_BREED, and then lastly print a line to the screen. | ||
|
||
## Task | ||
Lets try and run this application. The first thing we need to do is set the environment variable DOG_BREED. | ||
|
||
`export DOG_BREED=POODLE`{{execute}} | ||
|
||
After we set the environment variable lets run that script. | ||
|
||
`python printvar.py`{{execute}} | ||
|
||
If everything went well we should see some output on the screen. CONGRATS! | ||
|
||
So now that we have a working script, how do we distribute the script so that everyone can run it the same way every time without having to install all of the dependencies? DOCKER!!! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
FROM python:3-slim | ||
|
||
ADD printvar.py / | ||
|
||
CMD ["python", "./printvar.py"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
Containers offer a logical packaging mechanism in which applications can be abstracted from the environment in which they actually run. This decoupling allows container-based applications to be deployed easily and consistently, regardless of whether the target environment is a private data center, the public cloud, or even a developer’s personal laptop. This gives developers the ability to create predictable environments that are isolated from the rest of the applications and can be run anywhere. | ||
|
||
## Task | ||
Lets open the Dockerfile `Dockerfile`{{open}} and take a look at whats going on. We have a pretty simple dockerfile that pulls down a base python image. | ||
|
||
## Task | ||
For the next task let's add a few lines to the Dockerfile that will: | ||
1. Add our script to the root of the image - HINT use the ADD statement | ||
2. Execute that script - HINT use the CMD statement | ||
|
||
*TIP-If you are stuck with what to add to the Dockerfile there is a "Show Solution" button at the bottom the scenario.* | ||
|
||
## Task | ||
After we edit the Dockerfile, let's try to build our image. | ||
|
||
`docker build -t printvar-docker .`{{execute}} | ||
|
||
Next let's see if our image was created successfully. | ||
|
||
`docker images`{{execute}} | ||
|
||
We should see an image with a tag of `printvar-docker:latest`. Excellent | ||
|
||
## Task | ||
Lastly let's run our image and see our output. | ||
|
||
`docker run printvar-docker`{{execute}} | ||
|
||
We should see some output, but we see `None` for the variable we want. When we use the docker run command we can pass a flag of -e to pass the container a variable, lets try that now. | ||
|
||
`docker run -e DOG_BREED=POODLE printvar-docker`{{execute}} | ||
|
||
As you can imagine, if we had multiple environment variables, volume mounts, args, etc. that we had to pass to our container, that docker run command could get long and ugly. Lucky for us, docker-compose exists!! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
version: '3' | ||
services: | ||
printvars: | ||
build: . | ||
image: printvars-compose:latest | ||
environment: | ||
- DOG_BREED=HUSKY | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
Compose is a tool for defining and running multi-container Docker applications. With Compose, you use a YAML file to configure your application’s services. Then, with a single command, you create and start all the services (and their dependencies) from your configuration. In 3 Musketeers, it also simplifies our Makefiles. | ||
|
||
Our next task will be to add docker-compose. In order to do this we need a docker-compose.yml file. We will keep this file rather simple. If you open the docker-compose.yml file `docker-compose.yml`{{open}}, you will see we have a service named ```printvars```. Under printvars we have a build section (which builds our dockerfile) and an image section (which tags our image). | ||
|
||
## Task | ||
If you remember from the previous steps this script needs an environment variable to run correctly. We can pass environment variables to a container via a docker-compose environment block. Let's add a block to our docker-compose.yml file. | ||
|
||
*TIP-If you are stuck with what to add to the Dockerfile there is a "Show Solution" button at the bottom the scenario.* | ||
|
||
***PRO-TIP The environment section is really useful when your container excepts multiple variables. The next iteration of the environment block is the use of an env file. Check out the course https://www.katacoda.com/james5101/scenarios/make-docker-compose-env-variables for more info on using an envfile with 3musketers.*** | ||
|
||
## Task | ||
After our editing of the docker-compose file, let's try and build the container. | ||
|
||
`docker-compose build`{{execute}} | ||
|
||
The command above will produce a newly built printvars-compose image. Let's run the following command to confirm our image built. | ||
|
||
`docker images`{{execute}} | ||
|
||
## Task | ||
Let's try and run our image now via docker-compose up. Docker-compose up builds, (re)creates, starts and attaches containers for a service. You could also run ```docker-compose run servicename``` for one-off/adhoc tasks. | ||
`docker-compose up`{{execute}} | ||
|
||
## Task | ||
After creating our images and running our container we should be good samaritans and clean up after ourselves. We can do so by running docker-compose down | ||
`docker-compose down`{{execute}} | ||
|
||
|
||
|
||
This wraps up the section on docker-compose. Docker-compose is very powerful for running containers, for more info visit https://docs.docker.com/compose/. | ||
|
||
Now, onto the last Musketeer, Make! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
``` | ||
help: | ||
@fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/##//' | ||
build: ## build target will build our containers based on the docker-compose file. | ||
docker-compose build | ||
up: ## up will build and run our container based on the docker-compose file | ||
docker-compose up | ||
``` |
Oops, something went wrong.