Skip to content

Commit

Permalink
[Docker] Migrate aws to python
Browse files Browse the repository at this point in the history
  • Loading branch information
Herklos committed Oct 26, 2022
1 parent e0f5560 commit f07a576
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 18 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ COPY --from=base /opt/venv /opt/venv
# Add default config files
COPY octobot/config /octobot/octobot/config

COPY docker/*.sh /octobot/
COPY docker/* /octobot/

# 1. Install requirements
# 2. Add cloudflare gpg key and add cloudflare repo in apt repositories (from https://pkg.cloudflare.com/index.html)
Expand All @@ -44,7 +44,7 @@ RUN apt-get update \
&& curl -fsSL https://pkg.cloudflare.com/cloudflare-main.gpg | tee /usr/share/keyrings/cloudflare-main.gpg >/dev/null \
&& 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 \
&& apt-get update \
&& 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 \
&& 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 \
&& rm -rf /var/lib/apt/lists/* \
&& ln -s /opt/venv/bin/OctoBot OctoBot # Make sure we use the virtualenv \
&& chmod +x docker-entrypoint.sh
Expand Down
24 changes: 24 additions & 0 deletions docker/aws.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import os
import json
import re
from urllib.request import urlopen


def remove_special_chars(input_string):
return re.sub(r'[^a-zA-Z0-9_]', '', input_string)


if __name__ == '__main__':
# https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-metadata-endpoint-v4.html
container_metadata_url = os.getenv("ECS_CONTAINER_METADATA_URI_V4", None)
if container_metadata_url is not None:
try:
with urlopen(container_metadata_url + "/taskWithTags") as response:
body = response.read()
container_metadata = json.loads(body)
with open('.env', 'w') as env_file:
for key, value in container_metadata['TaskTags'].items():
env_file.write(remove_special_chars(
key) + "=" + value+"\n")
except Exception as e:
print("Error when requesting or parsing aws metadata")
10 changes: 0 additions & 10 deletions docker/aws.sh

This file was deleted.

3 changes: 2 additions & 1 deletion docker/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ if [[ -n "${OCTOBOT_CONFIG}" ]]; then
echo "$OCTOBOT_CONFIG" | tee /octobot/user/config.json >/dev/null
fi

bash aws.sh
python aws.py

bash tunnel.sh

./OctoBot
2 changes: 2 additions & 0 deletions docker/tunnel.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/bash

source .env

export TUNNEL_LOGFILE=/root/cloudflared.log
export TUNNEL_LOGLEVEL=info

Expand Down
5 changes: 0 additions & 5 deletions docker/util.sh

This file was deleted.

0 comments on commit f07a576

Please sign in to comment.