Skip to content

Commit

Permalink
reworked init script and added healthcheck
Browse files Browse the repository at this point in the history
  • Loading branch information
markglh committed Oct 5, 2017
1 parent a01727a commit cec958e
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 17 deletions.
11 changes: 8 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@ FROM localstack/localstack:$LOCALSTACK_DOCKER_IMAGE_TAG

COPY bootstrap /opt/bootstrap/

# Append our init script as a program in the supervisord config
RUN cat /opt/bootstrap/supervisord-init.conf >> /etc/supervisord.conf
RUN chmod +x /opt/bootstrap/scripts/init.sh
RUN chmod +x /opt/bootstrap/bootstrap.sh

RUN pip install awscli-local

RUN chmod +x /opt/bootstrap/scripts/init.sh

# We run the init script as a health check
# That way the container won't be healthy until it's completed successfully
# Once the init completes we wipe it to prevent it continiously running
HEALTHCHECK --start-period=10s --interval=1s --timeout=3s --retries=30\
CMD /opt/bootstrap/bootstrap.sh
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ By default the `init.sh` script creates an AWS stack using the CloudFormation te

Note that the CloudFormation template functionality provided by localstack isn't feature complete, [this](https://github.com/localstack/localstack/tree/master/tests/integration/templates) example `test` templates directory from localstack gives an indication of the currently supported featureset.

## Healthcheck
The image runs the bootstrapping scripts as a health check. This means that the service isn't considered `healthy` until they complete. This can therefore be used to control startup order within docker compose (see example below). **Do not override the health check!**

### Runtime overrides
Two options for overriding this at runtime:
- To just use a different CloudFormation template mount a Volume over `/opt/bootstrap/templates` containing a `cftemplate.yaml` template.
Expand All @@ -30,11 +33,11 @@ Two options for overriding this at runtime:
[awslocal](https://github.com/localstack/awscli-local) is installed and used for bootstrapping scripts.

# docker-compose
Here's an example compose file for running the container with kinesis, dynamodb, cloudwatch & Cloudformation.
Here's an example compose file for running the container with kinesis, dynamodb, cloudwatch & Cloudformation. Startup order is controlled using `depends_on`.
This mounts over the `cftemplate.yml` with a template in the same directory as the compose file:

```yaml
version: "3.3"
version: "2.3"

services:
localstack:
Expand All @@ -51,6 +54,12 @@ services:
ports:
- "4567-4582:4567-4582"
- "8080:8080"

some-service:
image: myorg/some-service
depends_on:
localstack:
condition: service_healthy
```
Note that the environment variables supply default values but can be overridden using a `.env` file.
Expand Down
4 changes: 4 additions & 0 deletions bootstrap/bootstrap.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash

# Let the healthcheck complete once, then wipe it out
/opt/bootstrap/scripts/init.sh && echo '#!/usr/bin/env bash' > /opt/bootstrap/bootstrap.sh
1 change: 0 additions & 1 deletion bootstrap/scripts/init.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
#!/usr/bin/env bash

awslocal cloudformation create-stack --template-body file:///opt/bootstrap/templates/cftemplate.yml --stack-name teststack
11 changes: 0 additions & 11 deletions bootstrap/supervisord-init.conf

This file was deleted.

0 comments on commit cec958e

Please sign in to comment.