Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: Docker #342

Merged
merged 9 commits into from
Nov 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.git/
.github/
log/*
!log/.keep
app/assets/builds/*
Expand All @@ -21,5 +22,9 @@ yarn-error.log
yarn-debug.log*
.yarn-integrity

# Ruby version is set in Dockerfile
.ruby-version

config/credentials/*
config/credentials.yml.enc
config/credentials.yml.enc
config/deploy/*
40 changes: 40 additions & 0 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Publish Docker Image to hub.docker.com

on:
release:
types: [published]

jobs:
push_to_registry:
name: Push Docker image to Docker Hub
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v4

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: bioportal/bioportal_web_ui

- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
68 changes: 35 additions & 33 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,53 +1,55 @@
# Make sure it matches the Ruby version in .ruby-version and Gemfile
ARG RUBY_VERSION=3.2.0
FROM ruby:${RUBY_VERSION}-alpine

# Install libvips for Active Storage preview support
RUN apk add --no-cache build-base \
libxml2-dev \
libxslt-dev \
mariadb-dev \
git \
tzdata \
nodejs yarn \
less \
bash \
docker \
docker-compose \
&& mkdir /node_modules

# Rails app lives here
ARG RUBY_VERSION=3.2
FROM ruby:${RUBY_VERSION}-slim-bookworm

WORKDIR /app

# Set production environment
RUN bash -c "set -o pipefail && apt-get update && \
apt-get install -y --no-install-recommends \
build-essential \
libxml2 \
libxslt-dev \
libmariadb-dev \
git \
curl \
&& curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key -o /etc/apt/keyrings/nodesource.asc \
&& echo 'deb [signed-by=/etc/apt/keyrings/nodesource.asc] https://deb.nodesource.com/node_20.x nodistro main' | tee /etc/apt/sources.list.d/nodesource.list \
&& apt-get update \
&& apt-get install -y --no-install-recommends nodejs \
&& corepack enable \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /usr/share/doc /usr/share/man \
&& mkdir /node_modules"

ARG RAILS_ENV="production"
ARG NODE_ENV="production"
ARG BUNDLE_WITHOUT="development test"

ENV RAILS_LOG_TO_STDOUT="1" \
RAILS_SERVE_STATIC_FILES="true" \
RAILS_ENV="${RAILS_ENV}" \
NODE_ENV="${NODE_ENV}" \
BUNDLE_PATH=/usr/local/bundle \
BUNDLE_WITHOUT="${BUNDLE_WITHOUT}"

RUN gem update --system 3.4.22 # the 3.4.22 can be removed if we support Ruby version > 3.0

COPY . .

#PATH="${PATH}:/node_modules/.bin"
COPY Gemfile* .
RUN bundle install
RUN yarn install && yarn build


COPY package.json *yarn* .
RUN yarn install

RUN cp config/bioportal_config_env.rb.sample config/bioportal_config_production.rb
RUN cp config/bioportal_config_env.rb.sample config/bioportal_config_development.rb
RUN cp config/database.yml.sample config/database.yml
COPY . .

# Precompile bootsnap code for faster boot times
RUN bundle exec bootsnap precompile --gemfile app/ lib/
RUN cp config/bioportal_config_env.rb.sample config/bioportal_config_production.rb \
&& cp config/bioportal_config_env.rb.sample config/bioportal_config_development.rb \
&& cp config/bioportal_config_env.rb.sample config/bioportal_config_test.rb \
&& cp config/database.yml.sample config/database.yml

RUN SECRET_KEY_BASE_DUMMY="1" ./bin/rails assets:precompile
RUN if [ "${RAILS_ENV}" != "development" ]; then \
bundle exec bootsnap precompile --gemfile app/ lib/ && \
SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile; fi

ENV BINDING="0.0.0.0"
EXPOSE 3000

CMD ["bash"]
CMD ["rails", "s"]
3 changes: 3 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,8 @@ GEM
netrc (0.11.0)
newrelic_rpm (9.14.0)
nio4r (2.7.3)
nokogiri (1.15.6-aarch64-linux)
racc (~> 1.4)
nokogiri (1.15.6-arm64-darwin)
racc (~> 1.4)
nokogiri (1.15.6-x86_64-linux)
Expand Down Expand Up @@ -553,6 +555,7 @@ GEM
zeitwerk (2.6.18)

PLATFORMS
aarch64-linux
arm64-darwin-22
x86_64-linux
x86_64-linux-musl
Expand Down
3 changes: 3 additions & 0 deletions bin/ontoportal
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ test() {
bin/run_api
fi

# create bioportal config file for test env if its not there.
[ -f config/bioportal_config_test.rb ] || cp config/bioportal_config_env.rb.sample config/bioportal_config_test.rb

echo "Running tests..."
echo "Run: API_URL=$api_url bundle exec rails test -v $test_options"

Expand Down
Loading