Bladeren bron

added basename option

tarfeef101 3 jaren geleden
bovenliggende
commit
0e093d8660
4 gewijzigde bestanden met toevoegingen van 7 en 1 verwijderingen
  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
 VOLUME /opt
 COPY entrypoint.sh /root/entrypoint.sh
+ENV BASENAME=0
 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
 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
-- `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.

+ 1 - 0
docker-compose.yaml

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

+ 3 - 0
entrypoint.sh

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