From 835fa2aca330c15f9bbf27bc522c97d12f9eb3a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrik=20Voto=C4=8Dek?= Date: Thu, 6 Jul 2023 12:41:11 +0200 Subject: [PATCH] feat(s3-cf): add script for deploying static sites --- Dockerfile | 8 +++-- .../download-aws-cli.sh | 0 scripts/deploy-s3-cf.sh | 29 +++++++++++++++++++ 3 files changed, 34 insertions(+), 3 deletions(-) rename download-aws-cli.sh => build-scripts/download-aws-cli.sh (100%) create mode 100755 scripts/deploy-s3-cf.sh diff --git a/Dockerfile b/Dockerfile index a7b9f6b..6e815af 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,8 +6,8 @@ WORKDIR /tmp RUN apt update && apt install -y curl zip ARG KUBECTL_VERSION -RUN curl -L "https://dl.k8s.io/release/v${KUBECTL_VERSION}/bin/linux/${TARGETARCH}/kubectl" -o /usr/local/kubectl -RUN chmod +x /usr/local/kubectl +RUN curl -L "https://dl.k8s.io/release/v${KUBECTL_VERSION}/bin/linux/${TARGETARCH}/kubectl" -o /usr/local/bin/kubectl +RUN chmod +x /usr/local/bin/kubectl ARG HELM_VERSION RUN curl -L "https://get.helm.sh/helm-v${HELM_VERSION}-linux-${TARGETARCH}.tar.gz" -o /tmp/helm.tar.gz @@ -20,9 +20,11 @@ ARG SENTRY_CLI_VERSION RUN curl -sL https://sentry.io/get-cli/ | INSTALL_DIR="/usr/local/bin" sh ARG AWS_CLI_VERSION -COPY download-aws-cli.sh /tmp/download-aws-cli.sh +COPY build-scripts/download-aws-cli.sh /tmp/download-aws-cli.sh RUN /tmp/download-aws-cli.sh +COPY scripts/deploy-s3-cf.sh /usr/local/bin/deploy-s3-cf + FROM cookielab/slim:12.0 RUN apt update && apt install -y curl jq \ diff --git a/download-aws-cli.sh b/build-scripts/download-aws-cli.sh similarity index 100% rename from download-aws-cli.sh rename to build-scripts/download-aws-cli.sh diff --git a/scripts/deploy-s3-cf.sh b/scripts/deploy-s3-cf.sh new file mode 100755 index 0000000..337e19f --- /dev/null +++ b/scripts/deploy-s3-cf.sh @@ -0,0 +1,29 @@ +#!/bin/sh + +set -xe + +MISSING_ENV=0 + +if [[ -z "${SOURCE_DIR}" ]]; then + echo "SOURCE_DIR env must be set" + MISSING_ENV=1 +fi + +if [[ -z "${AWS_S3_BUCKET}" ]]; then + echo "AWS_S3_BUCKET env must be set" + MISSING_ENV=1 +fi + +if [[ -z "${AWS_CF_DISTRIBUTION_ID}" ]]; then + echo "AWS_CF_DISTRIBUTION_ID env must be set" + MISSING_ENV=1 +fi + +if [[ "${MISSING_ENV}" == "1" ]]; then + exit 1 +fi + +aws s3 cp --recursive "${SOURCE_DIR}" "s3://${AWS_S3_BUCKET}/" +AWS_CF_INVALIDATION_ID="$(aws cloudfront create-invalidation --distribution-id ${AWS_CF_DISTRIBUTION_ID} --paths '/*' | jq -r .Invalidation.Id)" +echo "CloudFront Invalidation ID - ${AWS_CF_INVALIDATION_ID}" +aws cloudfront wait invalidation-completed --distribution-id ${AWS_CF_DISTRIBUTION_ID} --id ${AWS_CF_INVALIDATION_ID}