Skip to content

Commit 2b18ba2

Browse files
committed
Added examples and fixed env var import
1 parent fa050c9 commit 2b18ba2

File tree

7 files changed

+165
-8
lines changed

7 files changed

+165
-8
lines changed

Dockerfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,3 @@ WORKDIR /app
1818
RUN echo $PATH ; pip install pip -U --no-cache-dir && pip install wheel --no-cache-dir && pip install *.whl --no-cache-dir
1919
WORKDIR /
2020
ENTRYPOINT ["ecs_files_composer"]
21-
CMD ["-h"]

docker-compose.override.yaml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
---
2+
# Override file for local testing with config from the default env var
3+
4+
version: "3.8"
5+
services:
6+
ecs-local-endpoints:
7+
image: amazon/amazon-ecs-local-container-endpoints:latest-amd64
8+
volumes:
9+
- /var/run:/var/run
10+
- $HOME/.aws/:/home/.aws/
11+
environment:
12+
ECS_LOCAL_METADATA_PORT: "51679"
13+
HOME: "/home"
14+
AWS_DEFAULT_REGION: ${AWS_DEFAULT_REGION:-eu-west-1}
15+
AWS_PROFILE: ${AWS_PROFILE}
16+
ports:
17+
- 51679:51679
18+
19+
files-sidecar:
20+
environment:
21+
AWS_CONTAINER_CREDENTIALS_RELATIVE_URI: "/creds"
22+
AWS_DEFAULT_REGION: ${AWS_DEFAULT_REGION:-eu-west-1}
23+
ECS_CONFIG_CONTENT: |
24+
25+
files:
26+
/opt/files/test.txt:
27+
content: >-
28+
test from a yaml raw content
29+
owner: john
30+
group: root
31+
mode: 600
32+
/opt/files/aws.template:
33+
source:
34+
S3:
35+
BucketName: ${BUCKET_NAME:-sacrificial-lamb}
36+
Key: aws.yml
37+
38+
/opt/files/ssm.txt:
39+
source:
40+
Ssm:
41+
ParameterName: /cicd/shared/kms/arn
42+
commands:
43+
post:
44+
- file /opt/files/ssm.txt
45+
46+
/opt/files/secret.txt:
47+
source:
48+
Secret:
49+
SecretId: GHToken
50+
depends_on:
51+
- ecs-local-endpoints

docker-compose.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
# Docker compose base
3+
4+
version: "3.8"
5+
6+
volumes:
7+
localshared:
8+
9+
services:
10+
files-sidecar:
11+
volumes:
12+
- localshared:/opt/files/
13+
image: public.ecr.aws/compose-x/ecs-files-composer:v0.0.1
14+
deploy:
15+
resources:
16+
# Smallest RAM size for a lambda
17+
limits:
18+
cpus: 0.1
19+
memory: 128M
20+
build:
21+
context: ./

ecs_files_composer/cli.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,10 @@ def main():
3737
if not (args.env_var or args.ssm_config or args.s3_config or args.file_path) and environ.get(
3838
"ECS_CONFIG_CONTENT", None
3939
):
40-
config = environ.get("ECS_CONFIG_CONTENT")
40+
config = init_config(env_var="ECS_CONFIG_CONTENT")
41+
print("Config from default ECS_CONFIG_CONTENT", config)
4142
elif args.env_var:
42-
config = environ.get(args.env_var)
43+
config = init_config(env_var=args.env_var)
4344
elif args.file_path:
4445
config = init_config(file_path=args.file_path)
4546
elif args.ssm_config:

ecs_files_composer/ecs_files_composer.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,19 @@
88
import json
99
import re
1010
import subprocess
11-
import tempfile
1211
import warnings
1312
from os import environ, path
1413
from typing import Any
1514

1615
import boto3
1716
import yaml
18-
from boto3 import client, session
17+
from boto3 import session
1918
from botocore.exceptions import ClientError
2019
from botocore.response import StreamingBody
21-
from yaml import Dumper, Loader
20+
from yaml import Loader
2221

2322
from ecs_files_composer import input
24-
from ecs_files_composer.chmod import chmod
25-
from ecs_files_composer.common import LOG, keyisset, keypresent
23+
from ecs_files_composer.common import LOG, keyisset
2624
from ecs_files_composer.envsubst import expandvars
2725

2826

@@ -328,13 +326,15 @@ def init_config(
328326
raise Exception("No input source was provided")
329327
if not config_content:
330328
raise ImportError("Failed to import a configuration content")
329+
LOG.debug(config_content)
331330
try:
332331
config = yaml.load(config_content, Loader=Loader)
333332
except yaml.YAMLError:
334333
config = json.loads(config_content)
335334
except Exception:
336335
LOG.error("Input content is neither JSON nor YAML formatted")
337336
raise
337+
LOG.debug(config)
338338
return config
339339

340340

examples/kafka-connect.config.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
files:
2+
/opt/connect/truststore.jks:
3+
mode: 644
4+
source:
5+
S3:
6+
BucketName: ${CONNECT_BUCKET}
7+
Key: /cluster/${ENV}/truststore.jks
8+
/opt/connect/keystore.jks:
9+
mode: 644
10+
source:
11+
S3:
12+
BucketName: ${CONNECT_BUCKET}
13+
Key: /cluster/${ENV}/keystore.jks

examples/kafka-connect.yaml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
---
2+
# Example for injecting files into Kafka connect
3+
# Here we need to retrieve JKS files for our connect clients to connect to Kafka cluster(s)
4+
5+
version: "3.8"
6+
7+
services:
8+
9+
files-sidecar:
10+
deploy:
11+
labels:
12+
ecs.task.family: connect
13+
ecs.depends.condition: SUCCESS
14+
volumes:
15+
- localshared:/opt/connect
16+
environment:
17+
ENV: dev
18+
ECS_CONFIG_CONTENT: |
19+
20+
files:
21+
/opt/connect/truststore.jks:
22+
mode: 644
23+
source:
24+
S3:
25+
BucketName: ${CONNECT_BUCKET}
26+
Key: /cluster/${ENV}/truststore.jks
27+
/opt/connect/keystore.jks:
28+
mode: 644
29+
source:
30+
S3:
31+
BucketName: ${CONNECT_BUCKET}
32+
Key: /cluster/${ENV}/keystore.jks
33+
34+
35+
# Here we have a very simple definition for the connect service. Note that we mount the same docker volume.
36+
# To avoid confusion we mount it to the same mount point as the files-sidecar, but that could change to another one.
37+
# With the deploy labels, we indicate to ECS Compose-X to group these two services into the same task definition.
38+
# The depends_on helps us to define that the files sidecar need to be started first
39+
40+
kafka-connect:
41+
image: public.ecr.aws/ews-network/confluentinc/cp-kafka-connect:6.2.0
42+
volumes:
43+
- localshared:/opt/connect/
44+
45+
deploy:
46+
resources:
47+
reservations:
48+
cpus: "2.0"
49+
memory: 2GB
50+
limits:
51+
cpus: "2.0"
52+
memory: "3.5GB"
53+
labels:
54+
ecs.task.family: connect
55+
depends_on:
56+
- files-sidecar
57+
58+
# The following section works with ECS Compose-X which will retrieve information about the bucket in the account,
59+
# provide IAM access to the TaskRole and expose an environment variable CONNECT_BUCKET to the files-sidecar.
60+
61+
x-s3:
62+
connect-bucket:
63+
Lookup:
64+
Tags:
65+
- BucketName: connect-bucket
66+
Settings:
67+
EnvNames: CONNECT_BUCKET
68+
Services:
69+
- name: files-sidecar
70+
access:
71+
bucket: ListOnly
72+
objects: ReadOnly

0 commit comments

Comments
 (0)