Skip to content

Commit

Permalink
feat(s3-cf): add script for deploying static sites
Browse files Browse the repository at this point in the history
  • Loading branch information
Vrtak-CZ committed Jul 6, 2023
1 parent 34de09e commit 835fa2a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
8 changes: 5 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 \
Expand Down
File renamed without changes.
29 changes: 29 additions & 0 deletions scripts/deploy-s3-cf.sh
Original file line number Diff line number Diff line change
@@ -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}

0 comments on commit 835fa2a

Please sign in to comment.