Skip to content

Commit e0f5560

Browse files
committed
[Docker] Load env from tags when using AWS ECS
1 parent 67e3404 commit e0f5560

File tree

5 files changed

+31
-12
lines changed

5 files changed

+31
-12
lines changed

Dockerfile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,21 @@ COPY --from=base /opt/venv /opt/venv
3030
# Add default config files
3131
COPY octobot/config /octobot/octobot/config
3232

33-
COPY docker-entrypoint.sh docker-entrypoint.sh
33+
COPY docker/*.sh /octobot/
3434

3535
# 1. Install requirements
3636
# 2. Add cloudflare gpg key and add cloudflare repo in apt repositories (from https://pkg.cloudflare.com/index.html)
3737
# 3. Install required packages
3838
# 4. Finish env setup
3939
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
40-
RUN apt-get update \
40+
RUN apt-get update \
4141
&& apt-get install -y --no-install-recommends curl \
42-
&& mkdir -p /usr/share/keyrings \
42+
&& mkdir -p /usr/share/keyrings \
4343
&& chmod 0755 /usr/share/keyrings \
4444
&& curl -fsSL https://pkg.cloudflare.com/cloudflare-main.gpg | tee /usr/share/keyrings/cloudflare-main.gpg >/dev/null \
4545
&& echo 'deb [signed-by=/usr/share/keyrings/cloudflare-main.gpg] https://pkg.cloudflare.com/cloudflared buster main' | tee /etc/apt/sources.list.d/cloudflared.list \
4646
&& apt-get update \
47-
&& apt-get install -y --no-install-recommends curl cloudflared libxslt-dev libxcb-xinput0 libjpeg62-turbo-dev zlib1g-dev libblas-dev liblapack-dev libatlas-base-dev libopenjp2-7 libtiff-dev \
47+
&& apt-get install -y --no-install-recommends jq curl cloudflared libxslt-dev libxcb-xinput0 libjpeg62-turbo-dev zlib1g-dev libblas-dev liblapack-dev libatlas-base-dev libopenjp2-7 libtiff-dev \
4848
&& rm -rf /var/lib/apt/lists/* \
4949
&& ln -s /opt/venv/bin/OctoBot OctoBot # Make sure we use the virtualenv \
5050
&& chmod +x docker-entrypoint.sh

docker/aws.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
3+
source util.sh
4+
5+
# https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-metadata-endpoint-v4.html
6+
if [[ -n "$ECS_CONTAINER_METADATA_URI_V4" ]]; then
7+
AWS_TASK_WITH_TAGS_DETAILS=$(curl --silent "$ECS_CONTAINER_METADATA_URI_V4/taskWithTags")
8+
AWS_TASK_TAGS=$(echo $AWS_TASK_WITH_TAGS_DETAILS | jq -r ".TaskTags")
9+
json_to_env "$AWS_TASK_TAGS"
10+
fi

docker/docker-entrypoint.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
3+
##### OctoBot config #####
4+
if [[ -n "${OCTOBOT_CONFIG}" ]]; then
5+
echo "$OCTOBOT_CONFIG" | tee /octobot/user/config.json >/dev/null
6+
fi
7+
8+
bash aws.sh
9+
bash tunnel.sh
10+
11+
./OctoBot
Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,10 @@
11
#!/bin/bash
22

3-
# OctoBot user config from env
4-
if [[ -n "${OCTOBOT_CONFIG}" ]]; then
5-
echo "$OCTOBOT_CONFIG" | tee /octobot/user/config.json > /dev/null
6-
fi
7-
8-
##### CLOUDFLARED #####
93
export TUNNEL_LOGFILE=/root/cloudflared.log
104
export TUNNEL_LOGLEVEL=info
115

126
# start cloudflared if token is provided
7+
# https://developers.cloudflare.com/cloudflare-one/tutorials/cli/
138
if [[ -n "$CLOUDFLARE_TOKEN" ]]; then
149
cloudflared tunnel --url http://localhost:5001 --no-autoupdate run --token $CLOUDFLARE_TOKEN &
1510
fi
16-
17-
./OctoBot

docker/util.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
3+
json_to_env() {
4+
for s in $(echo $1 | jq -r 'keys[] as $k | "export \($k)=\(.[$k])"'); do export $s; done
5+
}

0 commit comments

Comments
 (0)