mirror of
https://github.com/docker/compose.git
synced 2025-07-07 05:44:25 +02:00
Adding the demo from AWS C3.
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
parent
6f916ab9ce
commit
2586fa35d4
25
ecs/demo/Makefile
Normal file
25
ecs/demo/Makefile
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
REPO_NAMESPACE ?= ${USER}
|
||||||
|
FRONTEND_IMG = ${REPO_NAMESPACE}/timestamper
|
||||||
|
REGISTRY_ID ?= PUT_ECR_REGISTRY_ID_HERE
|
||||||
|
DOCKER_PUSH_REPOSITORY=dkr.ecr.us-west-2.amazonaws.com
|
||||||
|
|
||||||
|
all: build-image
|
||||||
|
|
||||||
|
create-ecr:
|
||||||
|
aws ecr create-repository --repository-name ${FRONTEND_IMG}
|
||||||
|
|
||||||
|
build-image:
|
||||||
|
docker build -t $(REGISTRY_ID).$(DOCKER_PUSH_REPOSITORY)/$(FRONTEND_IMG) ./app
|
||||||
|
docker build -t $(FRONTEND_IMG) ./app
|
||||||
|
|
||||||
|
push-image-ecr:
|
||||||
|
aws ecr get-login-password --region us-west-2 | docker login -u AWS --password-stdin $(REGISTRY_ID).$(DOCKER_PUSH_REPOSITORY)
|
||||||
|
docker push $(REGISTRY_ID).$(DOCKER_PUSH_REPOSITORY)/$(FRONTEND_IMG)
|
||||||
|
|
||||||
|
push-image-hub:
|
||||||
|
docker push $(FRONTEND_IMG)
|
||||||
|
|
||||||
|
clean:
|
||||||
|
@docker context use default
|
||||||
|
@docker context rm aws || true
|
||||||
|
@docker-compose rm -f || true
|
107
ecs/demo/README.md
Normal file
107
ecs/demo/README.md
Normal file
@ -0,0 +1,107 @@
|
|||||||
|
## Compose sample application
|
||||||
|
|
||||||
|
### Python/Flask application
|
||||||
|
|
||||||
|
```
|
||||||
|
+--------------------+ +------------------+
|
||||||
|
| | | |
|
||||||
|
| Python Flask | timestamps | Redis |
|
||||||
|
| Application |------------->| |
|
||||||
|
| | | |
|
||||||
|
+--------------------+ +------------------+
|
||||||
|
```
|
||||||
|
|
||||||
|
### Things you'll need to do.
|
||||||
|
|
||||||
|
There are a number of places you'll need to fill in information. You can find them with:
|
||||||
|
|
||||||
|
```
|
||||||
|
grep -r '<<<' ./*
|
||||||
|
./docker-compose.yml: x-aws-pull_credentials: <<<your arn for your secret you can get with docker ecs secret list>>>
|
||||||
|
./docker-compose.yml: image: <<<yourhubname>>>/timestamper
|
||||||
|
## Walk through
|
||||||
|
```
|
||||||
|
|
||||||
|
### Setup pull credentials for private Docker Hub repositories
|
||||||
|
|
||||||
|
You should use a Personal Access Token (PAT) vs your default password. If you have 2FA enabled on your Hub account you will have to create a PAT. You can read more about managing access tokens here: https://docs.docker.com/docker-hub/access-tokens/
|
||||||
|
|
||||||
|
```
|
||||||
|
docker ecs secret create -d MyKey -u myhubusername -p myhubpat
|
||||||
|
```
|
||||||
|
|
||||||
|
### Create an AWS Docker context and list available contexts
|
||||||
|
|
||||||
|
```
|
||||||
|
docker ecs setup
|
||||||
|
Enter context name: aws
|
||||||
|
✔ sandbox.devtools.developer
|
||||||
|
Enter cluster name:
|
||||||
|
Enter region: us-west-2
|
||||||
|
✗ Enter credentials:
|
||||||
|
|
||||||
|
docker context ls
|
||||||
|
NAME DESCRIPTION DOCKER ENDPOINT KUBERNETES ENDPOINT ORCHESTRATOR
|
||||||
|
aws
|
||||||
|
default * Current DOCKER_HOST based configuration unix:///var/run/docker.sock swarm
|
||||||
|
```
|
||||||
|
|
||||||
|
### Test locally
|
||||||
|
|
||||||
|
```
|
||||||
|
docker context use default
|
||||||
|
docker-compose up
|
||||||
|
open http://localhost:5000
|
||||||
|
```
|
||||||
|
|
||||||
|
### Push images to hub for ecs (ecs cannot see your local image cache)
|
||||||
|
|
||||||
|
```
|
||||||
|
docker-compose push
|
||||||
|
```
|
||||||
|
|
||||||
|
### Switch to ECS context and launch the app
|
||||||
|
|
||||||
|
```
|
||||||
|
docker context use aws
|
||||||
|
docker ecs compose up
|
||||||
|
```
|
||||||
|
|
||||||
|
### Check out the CLI
|
||||||
|
|
||||||
|
```
|
||||||
|
docker ecs compose ps
|
||||||
|
docker ecs compose logs
|
||||||
|
```
|
||||||
|
|
||||||
|
### Check out the aws console
|
||||||
|
|
||||||
|
- cloud formation
|
||||||
|
- cloud watch
|
||||||
|
- security groups
|
||||||
|
- Load balancers (ELB for this example / ALB if your app only uses 80/443)
|
||||||
|
|
||||||
|
### Checkout cloudformation
|
||||||
|
|
||||||
|
```
|
||||||
|
docker ecs compose convert
|
||||||
|
```
|
||||||
|
|
||||||
|
### Stop the meters
|
||||||
|
|
||||||
|
```
|
||||||
|
docker ecs compose down
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
## Using Amazon ECR instead of Docker Hub
|
||||||
|
|
||||||
|
[Makefile](Makefile) has an example setup for creating an ECR repository and pushing to it. You'll need to have the AWS CLI installed and your AWS credentials available.
|
||||||
|
|
||||||
|
```
|
||||||
|
make create-ecr
|
||||||
|
REGISTRY_ID=<from the create above> make build-image
|
||||||
|
REGISTRY_ID=<from the create above> make push-image-ecr
|
||||||
|
```
|
||||||
|
|
||||||
|
If you want to use this often, you'll likely want to replace `PUT_ECR_REGISTRY_ID_HERE` with the value from above.
|
7
ecs/demo/app/Dockerfile
Normal file
7
ecs/demo/app/Dockerfile
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
FROM python:3.7-alpine
|
||||||
|
WORKDIR /app
|
||||||
|
COPY requirements.txt /app
|
||||||
|
RUN pip3 install -r requirements.txt
|
||||||
|
COPY . /app
|
||||||
|
ENTRYPOINT ["/app/scripts/entrypoint.sh"]
|
||||||
|
CMD ["python3", "app.py"]
|
19
ecs/demo/app/app.py
Normal file
19
ecs/demo/app/app.py
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
|
||||||
|
from flask import Flask
|
||||||
|
from flask import render_template
|
||||||
|
from redis import StrictRedis
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
app = Flask(__name__)
|
||||||
|
redis = StrictRedis(host='backend', port=6379)
|
||||||
|
|
||||||
|
|
||||||
|
@app.route('/')
|
||||||
|
def home():
|
||||||
|
redis.lpush('times', datetime.now().strftime('%Y-%m-%dT%H:%M:%S%z'))
|
||||||
|
return render_template('index.html', title='Home',
|
||||||
|
times=redis.lrange('times', 0, -1))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
app.run(host='0.0.0.0', debug=True)
|
2
ecs/demo/app/requirements.txt
Normal file
2
ecs/demo/app/requirements.txt
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
flask
|
||||||
|
redis
|
4
ecs/demo/app/scripts/entrypoint.sh
Executable file
4
ecs/demo/app/scripts/entrypoint.sh
Executable file
@ -0,0 +1,4 @@
|
|||||||
|
#! /bin/sh
|
||||||
|
|
||||||
|
if [ "${LOCALDOMAIN}" != "" ]; then echo "search ${LOCALDOMAIN}" >> /etc/resolv.conf; fi
|
||||||
|
exec "$@"
|
125
ecs/demo/app/templates/index.html
Normal file
125
ecs/demo/app/templates/index.html
Normal file
@ -0,0 +1,125 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<!-- Required meta tags -->
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<meta
|
||||||
|
name="viewport"
|
||||||
|
content="width=device-width, initial-scale=1, shrink-to-fit=yes"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<!-- Bootstrap CSS -->
|
||||||
|
<link
|
||||||
|
rel="stylesheet"
|
||||||
|
href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css"
|
||||||
|
integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS"
|
||||||
|
crossorigin="anonymous"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<title>Hello, Docker!</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="container">
|
||||||
|
<nav class="navbar sticky-top navbar-expand-lg navbar-dark bg-dark">
|
||||||
|
<a class="navbar-brand" href="/">Demo</a>
|
||||||
|
<button
|
||||||
|
class="navbar-toggler"
|
||||||
|
type="button"
|
||||||
|
data-toggle="collapse"
|
||||||
|
data-target="#navbarNav"
|
||||||
|
aria-controls="navbarNav"
|
||||||
|
aria-expanded="false"
|
||||||
|
aria-label="Toggle navigation"
|
||||||
|
>
|
||||||
|
<span class="navbar-toggler-icon"></span>
|
||||||
|
</button>
|
||||||
|
<div class="collapse navbar-collapse" id="navbarNav">
|
||||||
|
<ul class="navbar-nav">
|
||||||
|
<li class="nav-item dropdown">
|
||||||
|
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||||
|
Compose Spec
|
||||||
|
</a>
|
||||||
|
<div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
|
||||||
|
<a class="dropdown-item" href="https://compose-spec.io/">Overview</a>
|
||||||
|
<a class="dropdown-item" href="https://github.com/compose-spec/compose-spec/blob/master/spec.md">Specification</a>
|
||||||
|
<a class="dropdown-item" href="https://github.com/docker/awesome-compose">Awesome Compose - Compose Examples</a>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
<li class="nav-item dropdown">
|
||||||
|
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||||
|
Get Docker Desktop
|
||||||
|
</a>
|
||||||
|
<div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
|
||||||
|
<a class="dropdown-item" href="https://download.docker.com/mac/stable/Docker.dmg?utm_source=demo&utm_medium=web%20referral&utm_campaign=awsc32020&utm_budget=">Mac</a>
|
||||||
|
<a class="dropdown-item" href="https://download.docker.com/win/stable/Docker%20Desktop%20Installer.exe?utm_source=demo&utm_medium=web%20referral&utm_campaign=awsc32020&utm_budget=">Windows</a>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link" href="https://hub.docker.com/signup?utm_source=demo&utm_medium=web%20referral&utm_campaign=awsc32020&utm_budget="
|
||||||
|
>Sign up for Docker Hub</a
|
||||||
|
>
|
||||||
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link" href="https://docs.aws.amazon.com/AmazonECS/latest/developerguide/Welcome.html"
|
||||||
|
>Amazon ECS Docs</a
|
||||||
|
>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
<br />
|
||||||
|
<h1>Hello, Docker Folks!</h1>
|
||||||
|
<br />
|
||||||
|
|
||||||
|
<div class="container-sm">
|
||||||
|
<div class="text-center">
|
||||||
|
<!-- Button trigger modal -->
|
||||||
|
<a class="btn btn-primary" href="/">
|
||||||
|
Timestamp!
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<br />
|
||||||
|
|
||||||
|
<div class="table-responsive">
|
||||||
|
<table class="table table-striped table-hover table-sm">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th scope="col">Timestamp</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% for t in times %}
|
||||||
|
<tr>
|
||||||
|
<td>{{ t.decode('utf-8') }}</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Optional JavaScript -->
|
||||||
|
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
|
||||||
|
<script
|
||||||
|
src="https://code.jquery.com/jquery-3.3.1.slim.min.js"
|
||||||
|
integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo"
|
||||||
|
crossorigin="anonymous"
|
||||||
|
></script>
|
||||||
|
<script
|
||||||
|
src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js"
|
||||||
|
integrity="sha384-wHAiFfRlMFy6i5SRaxvfOCifBUQy1xHdJ/yoi7FRNXMRBu5WHdZYu1hA6ZOblgut"
|
||||||
|
crossorigin="anonymous"
|
||||||
|
></script>
|
||||||
|
<script
|
||||||
|
src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js"
|
||||||
|
integrity="sha384-B0UglyR+jN6CkvvICOB2joaf5I4l3gm9GU6Hc1og6Ls7i6U/mkkaduKaBhlAXv9k"
|
||||||
|
crossorigin="anonymous"
|
||||||
|
></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
12
ecs/demo/docker-compose.yml
Normal file
12
ecs/demo/docker-compose.yml
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
version: "3.8"
|
||||||
|
services:
|
||||||
|
frontend:
|
||||||
|
build: app
|
||||||
|
x-aws-pull_credentials: <<<your arn for your secret you can get with docker ecs secret list>>>
|
||||||
|
image: <<<yourhubname>>>/timestamper
|
||||||
|
ports:
|
||||||
|
- "5000:5000"
|
||||||
|
depends_on:
|
||||||
|
- backend
|
||||||
|
backend:
|
||||||
|
image: redis:alpine
|
Loading…
x
Reference in New Issue
Block a user