Skip to content

Commit

Permalink
Add Docker image for fake VM
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholasjackson committed Oct 25, 2019
1 parent 4394d57 commit ecaa827
Show file tree
Hide file tree
Showing 11 changed files with 239 additions and 3 deletions.
8 changes: 6 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,14 @@ jobs:
command: docker login -u ${DOCKER_USER} -p ${DOCKER_PASS}
- run:
name: docker build
command: docker build -t nicholasjackson/fake-service:${CIRCLE_TAG} .
command: |
docker build -t nicholasjackson/fake-service:${CIRCLE_TAG} .
docker build -t nicholasjackson/fake-service:vm-${CIRCLE_TAG} -f Dockerfile-VM .
- run:
name: docker push
command: docker push nicholasjackson/fake-service:${CIRCLE_TAG}
command: |
docker push nicholasjackson/fake-service:${CIRCLE_TAG}
docker push nicholasjackson/fake-service:vm-${CIRCLE_TAG}
publish-github-release:
docker:
Expand Down
25 changes: 25 additions & 0 deletions Dockerfile-VM
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# This image contains Fake Service Consul and Envoy, it can be used to simulate a Virtual Machine containing the Consul Agent
# and Envoy running as Daemon processes.
FROM nicholasjackson/consul-envoy:v1.6.1-v0.10.0

# Setup bash and supervisord etc
RUN apk add --update bash supervisor curl vim jq
RUN sed -i 's/\/bin\/ash/\/bin\/bash/g' /etc/passwd

RUN mkdir -p /etc/supervisor.d/

COPY entrypoint.sh /entrypoint.sh

# Setup the supervisor d file
COPY fake-service.ini /etc/supervisor.d/fake-service.ini
RUN chmod +x /entrypoint.sh

# Run supervisord
RUN sed -i 's/;nodaemon=false/nodaemon=true/g' /etc/supervisord.conf

# add fake service
RUN mkdir app
COPY ./bin/fake-service-linux /app/fake-service

ENTRYPOINT ["/usr/bin/supervisord"]
CMD ["-c", "/etc/supervisord.conf"]
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version=v0.7.1
version=v0.7.5

protos:
protoc -I grpc/protos/ grpc/protos/api.proto --go_out=plugins=grpc:grpc/api
Expand All @@ -20,6 +20,7 @@ build_local: build_ui

build_docker: build_linux
docker build -t nicholasjackson/fake-service:${version} .
docker build -t nicholasjackson/fake-service:vm-${version} -f Dockerfile-VM .

run_downstream:
TRACING_ZIPKIN=/dev/null NAME=web HTTP_CLIENT_KEEP_ALIVES=false UPSTREAM_WORKERS=2 UPSTREAM_URIS="http://localhost:9091,grpc://localhost:9093" go run main.go
Expand Down
57 changes: 57 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/bin/bash

# Wait until Consul can be contacted
until consul members; do
echo "Waiting for Consul to start"
sleep 1
done

# If we do not need to register a service just run the command
if [ ! -z "$SERVICE_CONFIG" ]; then
# register the service with consul
echo "Registering service with consul $SERVICE_CONFIG"
consul services register ${SERVICE_CONFIG}

exit_status=$?
if [ $exit_status -ne 0 ]; then
echo "### Error writing service config: $file ###"
cat $file
echo ""
exit 1
fi
fi

# register any central config from individual files
if [ ! -z "$CENTRAL_CONFIG" ]; then
IFS=';' read -r -a configs <<< ${CENTRAL_CONFIG}

for file in "${configs[@]}"; do
echo "Writing central config $file"
consul config write $file

exit_status=$?
if [ $exit_status -ne 0 ]; then
echo "### Error writing central config: $file ###"
cat $file
echo ""
exit 1
fi
done
fi

# register any central config from a folder
if [ ! -z "$CENTRAL_CONFIG_DIR" ]; then
for file in `ls -v $CENTRAL_CONFIG_DIR/*`; do
echo "Writing central config $file"
consul config write $file
echo ""

exit_status=$?
if [ $exit_status -ne 0 ]; then
echo "### Error writing central config: $file ###"
cat $file
echo ""
exit 1
fi
done
fi
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Kind = "service-defaults"
Name = "api"

Protocol = "http"

MeshGateway = {
mode = "local"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Kind = "service-defaults"
Name = "web"

Protocol = "http"

MeshGateway = {
mode = "local"
}
23 changes: 23 additions & 0 deletions examples/docker-compose-consul/consul_config/config.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
data_dir = "/tmp/"
log_level = "DEBUG"

datacenter = "dc1"

server = true

bootstrap_expect = 1
ui = true

bind_addr = "0.0.0.0"
client_addr = "0.0.0.0"

ports {
grpc = 8502
}

connect {
enabled = true
}

advertise_addr = "10.5.0.2"
enable_central_service_config = true
60 changes: 60 additions & 0 deletions examples/docker-compose-consul/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
---

version: "3.3"

services:

consul:
image: consul:1.6.1
command: ["consul", "agent", "-config-file=/config/config.hcl", "-config-dir=/config"]
volumes:
- "./consul_config:/config"
ports:
- 8500:8500
networks:
vpcbr:
ipv4_address: 10.5.0.2

# Define web service and envoy sidecar proxy
web:
image: nicholasjackson/fake-service:vm-v0.7.5
environment:
LISTEN_ADDR: 0.0.0.0:9090
UPSTREAM_URIS: "http://localhost:9091"
MESSAGE: "Hello World"
NAME: "web"
SERVER_TYPE: "http"
CONSUL_SERVER: 10.5.0.2
CENTRAL_CONFIG_DIR: /central
SERVICE_ID: "web-v1"
volumes:
- "./service_config/web_v1.hcl:/config/web_v1.hcl"
- "./central_config:/central"
ports:
- "9090:9090"
networks:
vpcbr:
ipv4_address: 10.5.0.3

# Define web service and envoy sidecar proxy
api:
image: nicholasjackson/fake-service:vm-v0.7.5
environment:
LISTEN_ADDR: 0.0.0.0:9090
MESSAGE: "Hello World"
NAME: "api"
SERVER_TYPE: "http"
CONSUL_SERVER: 10.5.0.2
SERVICE_ID: "api-v1"
volumes:
- "./service_config/api_v1.hcl:/config/api_v1.hcl"
networks:
vpcbr:
ipv4_address: 10.5.0.4

networks:
vpcbr:
driver: bridge
ipam:
config:
- subnet: 10.5.0.0/16
11 changes: 11 additions & 0 deletions examples/docker-compose-consul/service_config/api_v1.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
service {
name = "api"
id = "api-v1"
port = 9090

# Required in order to allow registration of a sidecar
connect {
sidecar_service {
}
}
}
18 changes: 18 additions & 0 deletions examples/docker-compose-consul/service_config/web_v1.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
service {
name = "web"
id = "web-v1"
port = 9090

connect {
sidecar_service {

proxy {
upstreams {
destination_name = "api"
local_bind_address = "127.0.0.1"
local_bind_port = 9091
}
}
}
}
}
21 changes: 21 additions & 0 deletions fake-service.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[program:consul]
command=/usr/local/bin/consul agent -config-dir /config -client 0.0.0.0 -retry-join %(ENV_CONSUL_SERVER)s -bind 0.0.0.0 -grpc-port=8502 -data-dir /tmp -hcl "enable_central_service_config = true"
autorestart=true
priority=100

[program:envoy]
command=/bin/bash -c "/usr/local/bin/consul connect envoy -sidecar-for %(ENV_SERVICE_ID)s -envoy-binary /usr/local/bin/envoy"
autorestart=true
startretries=300
priority=200

[program:fake-service]
command=/app/fake-service
autorestart=true
startretries=300
priority=300

[program:register-service]
command=/entrypoint.sh
autorestart=false
priority=400

0 comments on commit ecaa827

Please sign in to comment.