Skip to content

Instantly share code, notes, and snippets.

@jsierles
Created May 11, 2021 20:47
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jsierles/27c1fb770c204bde1e8c6f5beb852844 to your computer and use it in GitHub Desktop.
Save jsierles/27c1fb770c204bde1e8c6f5beb852844 to your computer and use it in GitHub Desktop.
Deploying Rails assets as a CI step with Docker
# syntax = docker/dockerfile:experimental
FROM node
ARG NPM_TOKEN=no
ARG APP_ENV=production
ENV AWS_DEFAULT_REGION=ams3
ARG AWS_ACCESS_KEY_ID
ARG AWS_SECRET_ACCESS_KEY
RUN pip install awscli
WORKDIR /app
COPY bin/rsync-cache bin/rsync-cache
ENV NPM_TOKEN=${NPM_TOKEN}
RUN echo "registry=https://registry.npmjs.org/" > ~/.npmrc && echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
# Install javascript modules
COPY package.json yarn.lock ./
ARG BUILDKITE_BRANCH
RUN --mount=type=cache,target=/cache \
bin/rsync-cache /cache/${BUILDKITE_BRANCH} "tmp/cache/yarn" "yarn install --frozen-lockfile --cache-folder tmp/cache/yarn"
# Copy files required for webpack bundle compilation
COPY bin/build-js bin/build-js
COPY bin/build-js-checksum bin/build-js-checksum
COPY vendor/assets vendor/assets
COPY config/webpack config/webpack
COPY config/locales config/locales
COPY app/javascript app/javascript
COPY app/assets app/assets
COPY babel.config.js babel.config.js
COPY public public
# Precompile webpack bundles
RUN mkdir -p ./tmp/cache/babel
RUN --mount=type=cache,target=/cache \
bin/rsync-cache /cache/${BUILDKITE_BRANCH} "tmp/cache/babel" "yarn build"
COPY config/*.js config/
COPY .eslint* .
COPY tsconfig.json tsconfig.json
COPY .yarnclean .yarnclean
COPY test/javascripts test/javascripts
COPY bin bin
ARG BUILDKITE_COMMIT
ENV BUILDKITE_COMMIT=${BUILDKITE_COMMIT}
RUN bin/upload-assets
RUN bin/upload-assets-manifest
#!/bin/bash
#
set -eu
dirname="$(dirname $0)"
source $dirname/helpers.sh
retry 5 aws s3 cp --metadata commit=${BUILDKITE_COMMIT} --acl public-read --endpoint=https://ams3.digitaloceanspaces.com public/packs/production/assets-manifest.json s3://your-assets/packs/production/assets-manifest-${APP_ENV}.json
#!/bin/bash
#
set -eu
dirname="$(dirname $0)"
source $dirname/helpers.sh
retry 5 aws s3 sync --cache-control="public,max-age=31556952" --exclude assets-manifest.json --acl public-read --endpoint=https://ams3.digitaloceanspaces.com public s3://your-assets
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment