Skip to content

Commit

Permalink
Merge pull request #7 from best-friends/improve-docker-build
Browse files Browse the repository at this point in the history
Use original dockerfile
  • Loading branch information
rosylilly authored Apr 16, 2019
2 parents 8e0017c + e67ad30 commit a3a204d
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 4 deletions.
9 changes: 5 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,8 @@ jobs:
docker-build:
docker:
- image: circleci/python:3.6.4
environment:
DOCKER_BUILDKIT: "1"
working_directory: ~/projects/mastodon/
steps:
- run:
Expand All @@ -193,7 +195,8 @@ jobs:
aws configure set aws_secret_access_key $AWS_SECRET_ACCESS_KEY --profile default
aws configure set region ${AWS_DEFAULT_REGION} --profile default
- checkout
- setup_remote_docker
- setup_remote_docker:
version: 18.09.3
- run:
name: Login to Amazon ECR
command: |
Expand All @@ -203,16 +206,14 @@ jobs:
command: docker pull ${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_DEFAULT_REGION}.amazonaws.com/mastodon:latest
- run:
name: Build docker image
command: docker build -t mastodon:latest --cache-from ${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_DEFAULT_REGION}.amazonaws.com/mastodon:latest .
command: docker build -f Dockerfile.best-friends -t mastodon:latest --cache-from ${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_DEFAULT_REGION}.amazonaws.com/mastodon:latest .
- run:
name: Push docker image to ECR
command: |
docker tag mastodon:latest ${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_DEFAULT_REGION}.amazonaws.com/mastodon:latest
docker tag mastodon:latest ${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_DEFAULT_REGION}.amazonaws.com/mastodon:${CIRCLE_BRANCH}
docker tag mastodon:latest ${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_DEFAULT_REGION}.amazonaws.com/mastodon:${CIRCLE_SHA1}
docker push ${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_DEFAULT_REGION}.amazonaws.com/mastodon:latest
docker push ${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_DEFAULT_REGION}.amazonaws.com/mastodon:${CIRCLE_BRANCH}
docker push ${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_DEFAULT_REGION}.amazonaws.com/mastodon:${CIRCLE_SHA1}
workflows:
version: 2
Expand Down
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@ elasticsearch
npm-debug.log
yarn-error.log
yarn-debug.log
/spec
/dist
/nanobox
94 changes: 94 additions & 0 deletions Dockerfile.best-friends
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# syntax = docker/dockerfile:experimental

ARG DEBIAN_RELEASE=stretch
ARG NODE_VERSION=8.15.1
ARG RUBY_VERSION=2.6.1

FROM node:${NODE_VERSION}-${DEBIAN_RELEASE}-slim as node

FROM ruby:${RUBY_VERSION}-slim-${DEBIAN_RELEASE}

COPY --from=node /usr/local/ /usr/local/

ARG UID=991
ARG GID=991

RUN \
apt update && \
echo "Etc/UTC" > /etc/localtime && \
apt dist-upgrade -y && \
apt install -y \
build-essential \
git \
libicu-dev \
libidn11-dev \
libpq-dev \
libprotobuf-dev \
protobuf-compiler \
&& \
apt install -y --no-install-recommends \
bison \
bzip2 \
ca-certificates \
ffmpeg \
file \
git \
imagemagick \
libffi-dev \
libgdbm-dev \
libgdbm3 \
libgmp-dev \
libicu-dev \
libidn11 \
libidn11-dev \
libncurses5-dev \
libpq-dev \
libpq5 \
libprotobuf-dev \
libprotobuf10 \
libreadline-dev \
libreadline7 \
libssl-dev \
libssl1.1 \
libxml2-dev \
libxslt-dev \
libyaml-0-2 \
libyaml-dev \
procps \
protobuf-compiler \
tzdata \
whois \
zlib1g-dev \
&& \
gem install --no-document bundler && \
rm /usr/local/bin/yarn /usr/local/bin/yarnpkg && \
npm install --global --force yarn && \
addgroup --gid $GID mastodon && \
useradd -m -u $UID -g $GID -d /opt/mastodon mastodon && \
echo "mastodon:`head /dev/urandom | tr -dc A-Za-z0-9 | head -c 24 | mkpasswd -s -m sha-256`" | chpasswd && \
mkdir -p /opt/mastodon && \
chown mastodon:mastodon /opt/mastodon

WORKDIR /opt/mastodon

USER mastodon

ADD --chown=mastodon:mastodon Gemfile* /opt/mastodon/

RUN \
bundle config build.nokogiri --use-system-libraries && \
bundle install -j$(nproc) --deployment --without development test

ADD --chown=mastodon:mastodon package.json yarn.lock .yarnclean /opt/mastodon/

RUN \
yarn install --pure-lockfile && \
yarn cache clean

COPY --chown=mastodon:mastodon . /opt/mastodon

ENV RAILS_ENV=production
ENV NODE_ENV=production
ENV PATH=/opt/mastodon/bin:$PATH

RUN OTP_SECRET=precompile_placeholder SECRET_KEY_BASE=precompile_placeholder rails assets:precompile

0 comments on commit a3a204d

Please sign in to comment.