Skip to content

Commit 945d27b

Browse files
committed
feat: add docker
1 parent 08ecb2a commit 945d27b

4 files changed

Lines changed: 84 additions & 0 deletions

File tree

.dockerignore

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/.bundle/
2+
/.yardoc
3+
/_yardoc/
4+
/coverage/
5+
/doc/
6+
/pkg/
7+
/spec/reports/
8+
/tmp/
9+
10+
# rspec failure tracking
11+
.rspec_status
12+
13+
public/
14+
.cache/
15+
16+
log/
17+
18+
node_modules/
19+
20+
.vscode/
21+
/tags
22+
.gitignore

Dockerfile

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
FROM ruby:2.6-alpine3.11 as builder
2+
3+
# Install system dependencies & clean them up
4+
RUN apk add --no-cache --virtual \
5+
nodejs-dev yarn bash \
6+
tzdata build-base libffi-dev \
7+
curl git vim \
8+
libnotify-dev
9+
10+
FROM builder as bridgetownrb-app
11+
12+
# This is to fix an issue on Linux with permissions issues
13+
ARG USER_ID=${USER_ID:-1000}
14+
ARG GROUP_ID=${GROUP_ID:-1000}
15+
ARG DOCKER_USER=${DOCKER_USER:-user}
16+
ARG APP_DIR=${APP_DIR:-/home/user/snowpacker}
17+
18+
# Create a non-root user
19+
RUN addgroup -g $GROUP_ID -S $GROUP_ID
20+
RUN adduser --disabled-password -G $GROUP_ID --uid $USER_ID -S $DOCKER_USER
21+
22+
# Create and then own the directory to fix permissions issues
23+
RUN mkdir -p $APP_DIR
24+
RUN chown -R $USER_ID:$GROUP_ID $APP_DIR
25+
26+
# Define the user running the container
27+
USER $USER_ID:$GROUP_ID
28+
29+
# . now == $APP_DIR
30+
WORKDIR $APP_DIR
31+
32+
# COPY is run as a root user, not as the USER defined above, so we must chown it
33+
COPY --chown=$USER_ID:$GROUP_ID Gemfile* $APP_DIR/
34+
RUN gem install bundler
35+
RUN bundle install
36+
37+
CMD ["bundle", "exec", "rake", "test"]

docker-compose.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
version: "3"
2+
3+
services:
4+
web:
5+
build:
6+
context: .
7+
dockerfile: Dockerfile
8+
args:
9+
USER_ID: ${USER_ID:-1000}
10+
GROUP_ID: ${GROUP_ID:-1000}
11+
DOCKER_USER: ${DOCKER_USER:-user}
12+
APP_DIR: ${APP_DIR:-/home/user/bridgetown-app}
13+
14+
command: bash -c "bundle exec rake test"
15+
16+
volumes:
17+
- .:${APP_DIR:-/home/user/snowpacker}

docker.env

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Assign and export seperately to avoid masking return values.
2+
USER_ID=$(id -u "$USER")
3+
GROUP_ID=$(id -g "$USER")
4+
export USER_ID
5+
export GROUP_ID
6+
7+
export DOCKER_USER="user"
8+
export APP_DIR="/home/$DOCKER_USER/bridgetown"

0 commit comments

Comments
 (0)