Browse Source

added basename option

tarfeef101 3 years ago
parent
commit
0e093d8660
4 changed files with 7 additions and 1 deletions
  1. 1 0
      Dockerfile
  2. 2 1
      README.md
  3. 1 0
      docker-compose.yaml
  4. 3 0
      entrypoint.sh

+ 1 - 0
Dockerfile

@@ -2,4 +2,5 @@ FROM alpine:latest
 RUN apk add --no-cache aws-cli
 RUN apk add --no-cache aws-cli
 VOLUME /opt
 VOLUME /opt
 COPY entrypoint.sh /root/entrypoint.sh
 COPY entrypoint.sh /root/entrypoint.sh
+ENV BASENAME=0
 CMD /root/entrypoint.sh
 CMD /root/entrypoint.sh

+ 2 - 1
README.md

@@ -4,6 +4,7 @@ Run this container as a sidecar to other services in a deployment environment li
 ## Usage
 ## Usage
 Deploy the container in an environment where it inherits an IAM role (i.e. an ECS task role), or provide the environment variables necessary to get `aws-cli` to pick up the credentials. To specify what files to expose, set the following environment variables:
 Deploy the container in an environment where it inherits an IAM role (i.e. an ECS task role), or provide the environment variables necessary to get `aws-cli` to pick up the credentials. To specify what files to expose, set the following environment variables:
 - `BUCKET` should be the bucket you wish to retrieve the files from
 - `BUCKET` should be the bucket you wish to retrieve the files from
-- `FILES` is a `|`-delimited list of files within the bucket you wish to be exposed. Their full key will be used
+- `FILES` is a `|`-delimited list of files within the bucket you wish to be exposed. Their full key will be used unless you use the `BASENAME` flag.
+- `BASENAME` should be set to 1 if you want the files to be renamed to be only the basename (so `/opt/basename` vs `/opt/full/key/path/basename`).
 
 
 The files will be exposed in a volume in `/opt`, which you should then mount in to any other containers you wish to acccess the files.
 The files will be exposed in a volume in `/opt`, which you should then mount in to any other containers you wish to acccess the files.

+ 1 - 0
docker-compose.yaml

@@ -15,5 +15,6 @@ services:
       - AWS_SESSION_TOKEN=
       - AWS_SESSION_TOKEN=
       - FILES=
       - FILES=
       - BUCKET=
       - BUCKET=
+      - BASENAME=
     volumes:
     volumes:
       - ./mount:/opt
       - ./mount:/opt

+ 3 - 0
entrypoint.sh

@@ -3,6 +3,9 @@ OLDIFS=$IFS
 IFS='|'
 IFS='|'
 for each in $FILES; do
 for each in $FILES; do
   aws s3 cp s3://$BUCKET/$each /opt/$each
   aws s3 cp s3://$BUCKET/$each /opt/$each
+  if [ $FLAG -eq 1 ]; then
+    mv /opt/$each /opt/$(basename $each)
+  fi
 done
 done
 IFS=$OLDIFS
 IFS=$OLDIFS
 tail -f /dev/null
 tail -f /dev/null