diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 392840e56a20ff75793d4b69f9715bdacfd4af18..a18eef1ca14f85ab4b411bd3da107ac260a0cb1b 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -17,9 +17,7 @@ lint:dockerfile: - mkdir ~/.config - cp ./.hadolint.yaml ~/.config/hadolint.yaml script: - - | - set -eo pipefail - find . -name "Dockerfile" -execdir hadolint {} \; + - hadolint ./context/Dockerfile lint:shell-script: stage: test @@ -27,9 +25,7 @@ lint:shell-script: before_script: - shellcheck -V script: - - | - set -eo pipefail - find . -name "*.sh" -exec shellcheck {} \; + - shellcheck ./context/s3-purge.sh # # IMAGE BUILDS/PUSHES diff --git a/context/Dockerfile b/context/Dockerfile index c969c9dbc23b84a63930e07ebdbf9c383b242270..32a1b91e3b8d1475e0f64b5e792766ff488061b4 100644 --- a/context/Dockerfile +++ b/context/Dockerfile @@ -17,7 +17,9 @@ RUN apt-get update \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* +RUN touch /var/log/s3-purge + COPY s3-purge.sh /usr/local/bin/s3-purge COPY crontab /etc/cron.d/s3-purge -CMD ["tail", "-f", "/dev/null"] +CMD ["tail", "-f", "/var/log/s3-purge"] diff --git a/context/s3-purge.sh b/context/s3-purge.sh index 005a77a62b3603746ec1cd3b373b17312b0a25f5..9d22ef8fbe47c96873bef8312271e7391247ba53 100755 --- a/context/s3-purge.sh +++ b/context/s3-purge.sh @@ -6,11 +6,14 @@ export BUCKET_NAME EXPIRE_AGE_DAYS=$(cat /s3_expire_days) export EXPIRE_AGE_DAYS +echo '===' +date + s3cmd --config=/s3_config ls s3://"${BUCKET_NAME}" | while read -r line; do createDate=$(echo "$line"|awk '{print $1" "$2}') createDate=$(date -d"$createDate" +%s) - olderThan=$(date -d"-$EXPIRE_AGE_DAYS" +%s) + olderThan=$(date -d"-$EXPIRE_AGE_DAYS days" +%s) if [[ $createDate -lt $olderThan ]] then fileName=$(echo "$line"|awk '{print $4}') @@ -21,3 +24,5 @@ s3cmd --config=/s3_config ls s3://"${BUCKET_NAME}" | while read -r line; fi fi done; + +echo '---'