Skip to content

Commit

Permalink
feat: add docker files for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
masaakiaoyagi committed May 22, 2022
1 parent aabae85 commit 58bec40
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 0 deletions.
43 changes: 43 additions & 0 deletions Dockerfile
@@ -0,0 +1,43 @@
ARG RUBY_VERSION

FROM ruby:${RUBY_VERSION}-slim

ARG GROUPNAME=docker
ARG USERNAME=docker
ARG UID
ARG GID
ARG RUNTIME_PACKAGES="git less"
ARG BUILD_PACKAGES="build-essential"
ARG WORKSPACE_DIR=/workspace
ARG WORKSPACE_CONTAINER_DIR=/workspace-container

RUN set -x \
&& groupadd -g ${GID} ${GROUPNAME} \
&& useradd -u ${UID} -g ${GROUPNAME} -m ${USERNAME}

RUN set -x \
&& apt-get -y update \
&& apt-get -y upgrade \
&& apt-get -y install --no-install-recommends ${RUNTIME_PACKAGES} ${BUILD_PACKAGES}

RUN set -x \
&& mkdir -p ${WORKSPACE_DIR} \
&& chown -R ${UID}:${GID} ${WORKSPACE_DIR}
WORKDIR ${WORKSPACE_DIR}

RUN set -x \
&& mkdir -p ${WORKSPACE_CONTAINER_DIR} \
&& chown -R ${UID}:${GID} ${WORKSPACE_CONTAINER_DIR}

COPY --chown=${UID}:${GID} . .

USER ${UID}

RUN set -x \
&& gem install bundler \
&& bundle config path ${WORKSPACE_CONTAINER_DIR}/vendor/bundle \
&& bundle install \
&& mv Gemfile.lock ${WORKSPACE_CONTAINER_DIR}

ENV WORKSPACE_CONTAINER_DIR=${WORKSPACE_CONTAINER_DIR}
ENTRYPOINT ["/workspace/entrypoint.sh"]
37 changes: 37 additions & 0 deletions docker-compose.yml
@@ -0,0 +1,37 @@
x-base:
base: &base
build: &build
context: .
args: &build-args
UID: 1000
GID: 1000
volumes:
- .:/workspace

services:
"3.1":
<<: *base
image: rspec-context_helper.rb:3.1
build:
<<: *build
args:
<<: *build-args
RUBY_VERSION: 3.1

"3.0":
<<: *base
image: rspec-context_helper.rb:3.0
build:
<<: *build
args:
<<: *build-args
RUBY_VERSION: 3.0

"2.7":
<<: *base
image: rspec-context_helper.rb:2.7
build:
<<: *build
args:
<<: *build-args
RUBY_VERSION: 2.7
9 changes: 9 additions & 0 deletions entrypoint.sh
@@ -0,0 +1,9 @@
#!/bin/sh

cleanup() {
rm Gemfile.lock
}
trap cleanup EXIT

ln -sf ${WORKSPACE_CONTAINER_DIR}/Gemfile.lock .
$@

0 comments on commit 58bec40

Please sign in to comment.