Skip to content

add armhf/raspberry pi example stack #64

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 13 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions docker-compose.armhf.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
version: "2"

services:
vote:
build:
context: ./vote
dockerfile: Dockerfile.armhf
ports:
- "5000:80"
networks:
- front-tier
- back-tier

result:
build:
context: ./result
dockerfile: Dockerfile.armhf
ports:
- "5001:80"
- "5858:5858"
networks:
- front-tier
- back-tier

worker:
build:
context: ./worker
dockerfile: Dockerfile.jdk.armhf
networks:
- back-tier

redis:
image: armhf/redis:latest
container_name: redis
ports:
- "6379"
networks:
- back-tier

db:
build:
context: ./postgres
dockerfile: Dockerfile.armhf
container_name: db
volumes:
- "db-data:/var/lib/postgresql/data"
networks:
- back-tier

volumes:
db-data:

networks:
front-tier:
back-tier:
92 changes: 92 additions & 0 deletions docker-stack.armhf.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
version: "3"

services:
redis:
image: armhf/redis:latest
ports:
- "6379"
networks:
- frontend
deploy:
replicas: 1
update_config:
parallelism: 2
delay: 10s
restart_policy:
condition: on-failure

db:
image: gesellix/postgres:9.5-armhf
volumes:
- db-data:/var/lib/postgresql/data
networks:
- backend
deploy:
placement:
constraints: [node.role == manager]

vote:
image: gesellix/sample-vote:armhf
ports:
- 5000:80
networks:
- frontend
depends_on:
- redis
deploy:
replicas: 2
update_config:
parallelism: 2
restart_policy:
condition: on-failure

result:
image: gesellix/sample-result:armhf
ports:
- 5001:80
networks:
- backend
depends_on:
- db
deploy:
replicas: 2
update_config:
parallelism: 2
delay: 10s
restart_policy:
condition: on-failure

worker:
image: gesellix/sample-worker:armhf
networks:
- frontend
- backend
deploy:
mode: replicated
replicas: 1
labels: [APP=VOTING]
restart_policy:
condition: on-failure
delay: 10s
max_attempts: 3
window: 120s
placement:
constraints: [node.role == manager]

visualizer:
image: gesellix/sample-visualizer
ports:
- "8080:8080"
stop_grace_period: 1m30s
volumes:
- "/var/run/docker.sock:/var/run/docker.sock"
deploy:
placement:
constraints: [node.role == manager]

networks:
frontend:
backend:

volumes:
db-data:
14 changes: 14 additions & 0 deletions postgres/Dockerfile.armhf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM armhf/alpine:3.4

ENV LANG en_US.utf8
ENV PGDATA /var/lib/postgresql/data

RUN apk add -U --no-cache postgresql bash su-exec ca-certificates curl \
&& curl -sSL -o /docker-entrypoint.sh "https://github.com/raw/docker-library/postgres/master/9.5/alpine/docker-entrypoint.sh" \
&& apk del --purge -r ca-certificates curl \
&& mkdir -p /docker-entrypoint-initdb.d /run/postgresql \
&& chmod a+x /docker-entrypoint.sh

EXPOSE 5432
ENTRYPOINT [ "/docker-entrypoint.sh" ]
CMD [ "postgres", "-c", "listen_addresses=0.0.0.0" ]
16 changes: 16 additions & 0 deletions result/Dockerfile.armhf
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM armhf/node:6.9.1-slim

WORKDIR /app

RUN npm install -g nodemon
COPY package.json /app/package.json
RUN npm config set registry http://registry.npmjs.org
RUN npm install && npm ls
RUN mv /app/node_modules /node_modules

COPY . /app

ENV PORT 80
EXPOSE 80

CMD ["node", "server.js"]
18 changes: 18 additions & 0 deletions vote/Dockerfile.armhf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Using official python runtime base image
FROM armhf/python:2.7-alpine

# Set the application directory
WORKDIR /app

# Install our requirements.txt
COPY requirements.txt /app/requirements.txt
RUN pip install -r requirements.txt

# Copy our code from the current folder to /app inside the container
COPY . /app

# Make port 80 available for links and/or publish
EXPOSE 80

# Define our command to be run when launching the container
CMD ["gunicorn", "app:app", "-b", "0.0.0.0:80", "--log-file", "-", "--access-logfile", "-", "--workers", "4", "--keep-alive", "0"]
7 changes: 7 additions & 0 deletions vote/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import socket
import random
import json
import logging

logging.basicConfig(level=logging.INFO)

option_a = os.getenv('OPTION_A', "Cats")
option_b = os.getenv('OPTION_B', "Dogs")
Expand All @@ -13,7 +16,9 @@

def get_redis():
if not hasattr(g, 'redis'):
logging.info('connecting to redis...')
g.redis = Redis(host="redis", db=0, socket_timeout=5)
logging.info('connected to redis')
return g.redis

@app.route("/", methods=['POST','GET'])
Expand All @@ -26,9 +31,11 @@ def hello():

if request.method == 'POST':
redis = get_redis()
logging.info('writing to redis')
vote = request.form['vote']
data = json.dumps({'voter_id': voter_id, 'vote': vote})
redis.rpush('votes', data)
logging.info('wrote to redis')

resp = make_response(render_template(
'index.html',
Expand Down
1 change: 1 addition & 0 deletions worker/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
worker-jar-with-dependencies.jar
4 changes: 4 additions & 0 deletions worker/Dockerfile.j.armhf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM armhf/openjdk:8-jre
WORKDIR /worker
COPY ./worker-jar-with-dependencies.jar /worker/worker.jar
CMD ["java", "-jar", "/worker/worker.jar"]
11 changes: 11 additions & 0 deletions worker/Dockerfile.j.builder.armhf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM armhf/maven:jdk-8

WORKDIR /proj

# cache dependencies
COPY pom.xml /proj/pom.xml
COPY src /proj/src

RUN mvn package

CMD [ "ls", "-lisah", "target" ]
13 changes: 13 additions & 0 deletions worker/Dockerfile.jdk.armhf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM armhf/maven:jdk-8

WORKDIR /proj

# cache dependencies
COPY pom.xml /proj/pom.xml
RUN mvn dependency:resolve
RUN mvn verify

COPY src /proj/src
RUN mvn package

CMD ["java", "-jar", "target/worker-jar-with-dependencies.jar"]
3 changes: 2 additions & 1 deletion worker/src/main/java/worker/Worker.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,15 @@ static Jedis connectToRedis(String host) {
while (true) {
try {
conn.keys("*");
System.err.println("Connected to redis");
break;
} catch (JedisConnectionException e) {
System.err.println("Waiting for redis");
sleep(1000);
}
}

System.err.println("Connected to redis");
System.out.println("Redis server info:\n" + conn.info());
return conn;
}

Expand Down