Differences between revisions 1 and 2
Revision 1 as of 2022-03-15 21:40:19
Size: 884
Editor: PieterSmit
Comment:
Revision 2 as of 2022-06-28 00:45:53
Size: 1971
Editor: PieterSmit
Comment:
Deletions are marked like this. Additions are marked like this.
Line 30: Line 30:


 * AWS ECS docker entrypoint.sh script to add metadata on startup to .version.txt {{{
#!/bin/bash
# Container startups script.
# Allow for runtime configuration through env vars.
# https://12factor.net/build-release-run
set -e
echo "# Start container with $0 PWD=${PWD}"
echo "#"

# Get aws ecs container metadata, add to .version.txt if available.
if [[ -z "${ECS_CONTAINER_METADATA_URI_V4}" ]]; then
    echo "# Not running in ECS, probably local." | tee -a .version.txt
else
    echo "# aws ecs extracting metadata." | tee -a .version.txt
 echo "# curl -s ${ECS_CONTAINER_METADATA_URI_V4}" >> .version.txt
 curl -s "${ECS_CONTAINER_METADATA_URI_V4}" >> .version.txt || true
 echo "# aws ecs - The END." >> .version.txt
fi

echo "# cat .version.txt"
cat .version.txt
echo "#"

echo "# Add env vars REACT_APP_* to ''env.js'' at webserver root"
echo "export default () => (`jo -p \`env | grep REACT_APP_ | sed -e 's/[[:blank:]]/{_!!_}/g'\` end=1`)" | sed -e 's/{_!!_}/ /g' | tee env.js
echo "#"

echo "# Starting docker cmd \$@=$@ ..."
exec "$@"

}}}

DockerEntrypoint

  • Example entry point file
    • It creates a env.js file form environment variables - for use with SPA react/angular for runtime config
    • Add to Dockerfile as

      COPY Dockerentrypoint.sh /Dockerentrypoint.sh
      ENTRYPOINT [ "/Dockerentrypoint.sh" ]
    • at the last line it executes Docker CMD passed to docker

# Container startups script.
# Allow for runtime configuration through env vars.
# https://12factor.net/build-release-run
set -e
echo "# Start container with $0  PWD=${PWD}"
echo "#"

echo "# cat .version.txt"
cat .version.txt
echo "#"

echo "# Add env vars REACT_APP_* to ''env.js'' at webserver root"
echo "window.ENV = `jo -p \`env | grep REACT_APP_ | sed -e 's/[[:blank:]]/{_!!_}/g'\` end=1`" | sed -e 's/{_!!_}/ /g' | tee env.js
echo "#"

echo "# Starting docker cmd \$@=$@ ..."
exec "$@"
  • AWS ECS docker entrypoint.sh script to add metadata on startup to .version.txt

    # Container startups script.
    # Allow for runtime configuration through env vars.
    # https://12factor.net/build-release-run
    set -e
    echo "# Start container with $0  PWD=${PWD}"
    echo "#"
    
    # Get aws ecs container metadata, add to .version.txt if available.
    if [[ -z "${ECS_CONTAINER_METADATA_URI_V4}" ]]; then
        echo "# Not running in ECS, probably local." | tee -a .version.txt
    else
        echo "# aws ecs extracting metadata." | tee -a .version.txt
            echo "# curl -s ${ECS_CONTAINER_METADATA_URI_V4}" >> .version.txt
            curl -s "${ECS_CONTAINER_METADATA_URI_V4}" >> .version.txt || true
            echo "# aws ecs - The END." >> .version.txt
    fi
    
    echo "# cat .version.txt"
    cat .version.txt
    echo "#"
    
    echo "# Add env vars REACT_APP_* to ''env.js'' at webserver root"
    echo "export default () => (`jo -p \`env | grep REACT_APP_ | sed -e 's/[[:blank:]]/{_!!_}/g'\` end=1`)" | sed -e 's/{_!!_}/ /g' | tee env.js
    echo "#"
    
    echo "# Starting docker cmd \$@=$@ ..."
    exec "$@"

DockerEntrypoint (last edited 2023-06-17 03:43:41 by PieterSmit)