Skip to content

Instantly share code, notes, and snippets.

@drnic
Last active July 6, 2023 22:02
Show Gist options
  • Save drnic/9b69fbce024907cff632f80d9d839867 to your computer and use it in GitHub Desktop.
Save drnic/9b69fbce024907cff632f80d9d839867 to your computer and use it in GitHub Desktop.
# This is the Generic storeconnect_ci:latest build and
# can be reused to build individual app CI's.
# A Pre-built image of `storeconnect_ci:latest` is being
# store in AWS ECR at 040621143078.dkr.ecr.us-east-1.amazonaws.com/storeconnect_ci:latest
# NOTE: ARGs come from docker-compose:build/args
FROM debian:bullseye-slim
ARG PG_MAJOR='12'
ARG NODE_MAJOR='16'
ARG BUNDLE_GITHUB__COM
ENV BUNDLE_GITHUB__COM=$BUNDLE_GITHUB__COM
RUN apt-get update && apt-get install -y curl gnupg2 unzip git
# Add PostgreSQL to sources list
RUN curl -sSL https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - \
&& echo 'deb http://apt.postgresql.org/pub/repos/apt/ bullseye-pgdg main' $PG_MAJOR > /etc/apt/sources.list.d/pgdg.list
# Install dependencies
RUN apt-get update -qq && DEBIAN_FRONTEND=noninteractive apt-get -yq dist-upgrade && \
DEBIAN_FRONTEND=noninteractive apt-get install -yq --no-install-recommends \
build-essential \
postgresql-client-$PG_MAJOR \
libpq-dev && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* && \
truncate -s 0 /var/log/*log
# Install NodeJS
RUN curl -sL https://deb.nodesource.com/setup_$NODE_MAJOR.x | bash -
RUN apt-get install -y nodejs
# Install Chrome WebDriver
RUN CHROMEDRIVER_VERSION=`curl -sS chromedriver.storage.googleapis.com/LATEST_RELEASE` && \
mkdir -p /opt/chromedriver-$CHROMEDRIVER_VERSION && \
curl -sS -o /tmp/chromedriver_linux64.zip http://chromedriver.storage.googleapis.com/$CHROMEDRIVER_VERSION/chromedriver_linux64.zip && \
unzip -qq /tmp/chromedriver_linux64.zip -d /opt/chromedriver-$CHROMEDRIVER_VERSION && \
rm /tmp/chromedriver_linux64.zip && \
chmod +x /opt/chromedriver-$CHROMEDRIVER_VERSION/chromedriver && \
ln -fs /opt/chromedriver-$CHROMEDRIVER_VERSION/chromedriver /usr/local/bin/chromedriver
# Install Google Chrome
RUN curl -sS -o - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - && \
echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list && \
apt-get -yqq update && \
apt-get -yqq install google-chrome-stable && \
rm -rf /var/lib/apt/lists/*
# Add docker-compose-wait tool -------------------
ENV WAIT_VERSION 2.7.2
ADD https://github.com/ufoscout/docker-compose-wait/releases/download/$WAIT_VERSION/wait /wait
RUN chmod +x /wait
ARG BUILDKITE_PLUGIN_DOCKER_ECR_CACHE_EXPORT_IMAGE=retailreels
ARG BUILDKITE_PLUGIN_DOCKER_ECR_CACHE_EXPORT_TAG=bundle
FROM ${BUILDKITE_PLUGIN_DOCKER_ECR_CACHE_EXPORT_IMAGE}:${BUILDKITE_PLUGIN_DOCKER_ECR_CACHE_EXPORT_TAG}
# Configure bundler and PATH
ENV LANG=C.UTF-8 \
GEM_HOME=/bundle \
BUNDLE_JOBS=4 \
BUNDLE_RETRY=3
ENV BUNDLE_PATH $GEM_HOME
ENV BUNDLE_APP_CONFIG=$BUNDLE_PATH \
BUNDLE_BIN=$BUNDLE_PATH/bin
ENV BUNDLE_SILENCE_ROOT_WARNING=1
ENV YARN_PATH=/root/.yarn/bin
ENV PATH $APP_DIR/bin:$BUNDLE_BIN:$YARN_PATH:$PATH
ARG APP_DIR=/app
COPY Gemfile Gemfile.lock package.json yarn.lock $APP_DIR/
RUN gem install bundler -v $(grep 'BUNDLED WITH' -A1 $APP_DIR/Gemfile.lock | tail -n 1 )
RUN cd && set -x && ruby --version && gem --version && bundle --version
RUN echo "alias bake='bundle exec rake'" >> ~/.bashrc && \
echo "alias be='bundle exec'" >> ~/.bashrc && \
echo "alias cdcur='cd /app'" >> ~/.bashrc && \
echo "alias rs='bin/rails server'" >> ~/.bashrc && \
echo "alias rc='bin/rails console'" >> ~/.bashrc && \
echo "alias rt='bundle exec rspec'" >> ~/.bashrc
# Install dependencies
RUN cd $APP_DIR && yarn install
RUN cd $APP_DIR && bundle install
EXPOSE 3000
WORKDIR $APP_DIR
# Ruby build, based on the official Ruby Dockerfile at:
# https://github.com/ruby/ruby-docker-images
ARG BUILDKITE_PLUGIN_DOCKER_ECR_CACHE_EXPORT_IMAGE=retailreels
ARG BUILDKITE_PLUGIN_DOCKER_ECR_CACHE_EXPORT_TAG=ruby
FROM ${BUILDKITE_PLUGIN_DOCKER_ECR_CACHE_EXPORT_IMAGE}:${BUILDKITE_PLUGIN_DOCKER_ECR_CACHE_EXPORT_TAG}
ARG RUBY_VERSION
ENV LANG C.UTF-8
ENV DEBIAN_FRONTEND noninteractive
# Upgrade yarn
RUN curl --compressed -o- -L https://yarnpkg.com/install.sh | bash
ADD ruby_build_deps.txt /tmp/
RUN set -ex && \
apt-get update && \
apt-get install -y --no-install-recommends \
ca-certificates \
gcc \
g++ \
libffi-dev \
libgdbm-dev \
libgmp-dev \
libncurses5-dev \
libreadline-dev \
libssl-dev \
libyaml-dev \
make \
autoconf \
bison \
git \
tzdata \
zlib1g-dev \
$(cat /tmp/ruby_build_deps.txt) && \
apt-get clean && rm -r /var/lib/apt/lists/*
RUN set -ex && \
useradd -ms /bin/bash ubuntu
ADD install_ruby.sh /tmp/
RUN chmod +x /tmp/install_ruby.sh
ENV RUBY_VERSION=$RUBY_VERSION
ENV RUBYGEMS_VERSION=3.4.15
ARG optflags
ARG debugflags
ARG cppflags
RUN set -ex && \
# skip installing gem documentation
mkdir -p /usr/local/etc && \
{ \
echo 'install: --no-document'; \
echo 'update: --no-document'; \
} >> /usr/local/etc/gemrc && \
\
/tmp/install_ruby.sh && \
rm /tmp/install_ruby.sh && \
\
dpkg-query --show --showformat '${package}\n' \
| grep -P '^libreadline\d+$' \
| xargs apt-mark manual && \
\
rm /tmp/ruby_build_deps.txt
env:
RAILS_ENV: test
steps:
- label: ":docker: Docker image"
commands:
# A hack to pass the Docker image name:tag to docker-compose plugin's run.
# This relies on the implementation of docker-compose plugin:
# https://github.com/buildkite-plugins/docker-compose-buildkite-plugin/blob/v3.7.0/lib/metadata.bash#L28-L43
- buildkite-agent meta-data set docker-compose-plugin-built-image-tag-app-docker-compose.test.yml $$BUILDKITE_PLUGIN_DOCKER_IMAGE
plugins:
- seek-oss/docker-ecr-cache#v2.0.0:
max-age-days: 7
dockerfile: "Dockerfile"
cache-on:
- "Dockerfile"
- seek-oss/docker-ecr-cache#v2.0.0:
build-args:
- BUILDKITE_PLUGIN_DOCKER_ECR_CACHE_EXPORT_IMAGE
- BUILDKITE_PLUGIN_DOCKER_ECR_CACHE_EXPORT_TAG
- RUBY_VERSION=3.2.2
max-age-days: 7
dockerfile: "Dockerfile.ruby"
cache-on:
- ".tool-versions"
- seek-oss/docker-ecr-cache#v2.0.0:
build-args:
- BUILDKITE_PLUGIN_DOCKER_ECR_CACHE_EXPORT_IMAGE
- BUILDKITE_PLUGIN_DOCKER_ECR_CACHE_EXPORT_TAG
max-age-days: 7
dockerfile: "Dockerfile.bundle"
context: "."
cache-on:
- "yarn.lock"
- "Gemfile.lock"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment