Skip to content

Instantly share code, notes, and snippets.

@jhgaylor
Last active November 3, 2019 22:57
Show Gist options
  • Save jhgaylor/4b0f8c64bd16e6992770f7a4bf4decd6 to your computer and use it in GitHub Desktop.
Save jhgaylor/4b0f8c64bd16e6992770f7a4bf4decd6 to your computer and use it in GitHub Desktop.
Add arbitrary ssm paramters to an existing docker image as environment variables at run time

Check the upstream readme for more inforation on how to specify the desired ssm parameters https://github.com/binxio/ssm-get-parameter/blob/master/README.md

the idea is you just update image name in build.sh for your project and then use your custom docker image which wraps the image the project actually needs and then that ssm-get-parameter binary handles the env var translation of any env vars you set that have the magic ssm:// prefix in the value

#!/bin/bash
IMAGENAME="redis:latest"
docker pull $IMAGENAME
ORIGINAL_ENTRYPOINT=$(docker inspect --format='{{ .Config.Entrypoint }}' $IMAGENAME)
ORIGINAL_CMD=$(docker inspect --format='{{ .Config.Cmd }}' $IMAGENAME)
docker build --build-arg IMAGENAME=${IMAGENAME} --build-arg ORIGINAL_ENTRYPOINT=${ORIGINAL_ENTRYPOINT} --build-arg ORIGINAL_CMD=${ORIGINAL_CMD} -f Dockerfile .
FROM binxio/ssm-get-parameter AS SSMGETPARAM
ARG IMAGENAME
FROM $IMAGENAME
ARG ORIGINAL_ENTRYPOINT
ARG ORIGINAL_CMD
# install https://github.com/binxio/ssm-get-parameter
COPY --from SSMGETPARAM /ssm-get-parameter /usr/local/bin/
ENTRYPOINT /usr/local/bin/ssm-get-parameter
CMD ["/bin/bash", "-c", "${ORIGINAL_ENTRYPOINT}", "${ORIGINAL_CMD}"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment