Skip to content

Commit 8fb9500

Browse files
committed
Add app and workflow
1 parent a6e3c30 commit 8fb9500

File tree

6 files changed

+82
-1
lines changed

6 files changed

+82
-1
lines changed

.github/workflows/push.yml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name: Docker Compose Actions Workflow
2+
on: push
3+
jobs:
4+
test:
5+
runs-on: ubuntu-latest
6+
steps:
7+
- uses: actions/checkout@master
8+
- name: Build the stack
9+
run: docker-compose up -d
10+
- name: Test
11+
run: docker run --network container:webapp-frontend appropriate/curl -s --retry 10 --retry-connrefused http://localhost:5000/

Dockerfile

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
FROM python:3.7-alpine
2+
WORKDIR /code
3+
ENV FLASK_APP app.py
4+
ENV FLASK_RUN_HOST 0.0.0.0
5+
RUN apk add --no-cache gcc musl-dev linux-headers
6+
COPY requirements.txt requirements.txt
7+
RUN pip install -r requirements.txt
8+
COPY . .
9+
CMD ["flask", "run"]

README.md

+25-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,26 @@
11
# docker-compose-actions-workflow
2-
GitHub Actions workflow example using Docker Compose to build and test a multi-container stack
2+
3+
This is a GitHub Actions workflow example to demonstrate building and testing a multi-container stack using `docker-compose`.
4+
5+
This sample is based on the [Get started with Docker Compose](https://docs.docker.com/compose/gettingstarted/) documentation.
6+
7+
## GitHub Actions Workflow
8+
9+
**push.yml**
10+
```yml
11+
name: Docker Compose Actions Workflow
12+
on: push
13+
jobs:
14+
test:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@master
18+
- name: Build the stack
19+
run: docker-compose up -d
20+
- name: Test
21+
run: docker run --network container:webapp-frontend appropriate/curl -s --retry 10 --retry-connrefused http://localhost:5000/
22+
```
23+
24+
## License
25+
26+
MIT License - see the [LICENSE](LICENSE) file for details

app.py

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import time
2+
3+
import redis
4+
from flask import Flask
5+
6+
app = Flask(__name__)
7+
cache = redis.Redis(host='redis', port=6379)
8+
9+
10+
def get_hit_count():
11+
retries = 5
12+
while True:
13+
try:
14+
return cache.incr('hits')
15+
except redis.exceptions.ConnectionError as exc:
16+
if retries == 0:
17+
raise exc
18+
retries -= 1
19+
time.sleep(0.5)
20+
21+
22+
@app.route('/')
23+
def hello():
24+
count = get_hit_count()
25+
return 'Hello World! I have been seen {} times.\n'.format(count)

docker-compose.yml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
version: '3'
2+
services:
3+
web:
4+
container_name: webapp-frontend
5+
build: .
6+
ports:
7+
- "5000:5000"
8+
redis:
9+
container_name: redis-backend
10+
image: "redis:alpine"

requirements.txt

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
flask
2+
redis

0 commit comments

Comments
 (0)