Skip to content

Commit

Permalink
Merge branch 'feature/update-docker-compose' into test
Browse files Browse the repository at this point in the history
  • Loading branch information
syphax-bouazzouni committed Nov 15, 2023
2 parents 2fbf640 + 2e27635 commit 4f2f7d0
Show file tree
Hide file tree
Showing 17 changed files with 420 additions and 536 deletions.
142 changes: 6 additions & 136 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -1,137 +1,7 @@
# Default values are optimized for production to avoid having to configure
# much in production.
#
# However it should be easy to get going in development too. If you see an
# uncommented option that means it's either mandatory to set or it's being
# overwritten in development to make your life easier.
OP_API_KEY=8b5b7825-538d-40e0-9e9e-5ab9274a9aeb
OP_API_URL="https://data.bioontology.org"
STARTER_ONTOLOGY=STY

# Enable BuildKit by default:
# https://docs.docker.com/develop/develop-images/build_enhancements
export DOCKER_BUILDKIT=1

# Rather than use the directory name, let's control the name of the project.
export COMPOSE_PROJECT_NAME=ontoportal-docker

# In development we want all services to start but in production you don't
# need the asset watchers to run since assets get built into the image.
#
# You can even choose not to run postgres and redis in prod if you plan to use
# managed cloud services. Everything "just works", even optional depends_on!
#export COMPOSE_PROFILES=postgres,redis,web,worker,cable
export COMPOSE_PROFILES=db,cache,assets,web

# If you're running native Linux and your uid:gid isn't 1000:1000 you can set
# these to match your values before you build your image. You can check what
# your uid:gid is by running `id` from your terminal.
#export UID=1000
#export GID=1000

# You can generate a more secure secret by running: ./run rails secret
export SECRET_KEY_BASE=insecure_key_for_dev

# Which environment is running? These should be "development" or "production".
#export RAILS_ENV=production
#export NODE_ENV=production
export RAILS_ENV=development
export NODE_ENV=development

# The bind port for puma.
#
# Be warned that if you change this value you'll need to change 8000 in both
# your Dockerfile and in a few spots in docker-compose.yml due to the nature of
# how this value can be set (Docker Compose doesn't support nested ENV vars).
#export PORT=8000

# How many workers and threads should your app use? WEB_CONCURRENCY defaults
# to the server's CPU count * 2. That is a good starting point. In development
# it's a good idea to use 1 to avoid race conditions when debugging.
#export WEB_CONCURRENCY=
#export RAILS_MAX_THREADS=5
#export WEB_CONCURRENCY=1
#export RAILS_MAX_THREADS=1

# You'll always want to set POSTGRES_USER and POSTGRES_PASSWORD since the
# postgres Docker image uses them for its default database user and password.
export POSTGRES_USER=hello
export POSTGRES_PASSWORD=password
#export POSTGRES_DB=hello
#export POSTGRES_HOST=postgres
#export POSTGRES_PORT=5432

# What's your full Redis connection URL? This will be used for caching, Sidekiq,
# and Action Cable. You can always split them up later.
#export REDIS_URL=redis://redis:6379/1

# The bind port for puma but for Action Cable.
#
# Be warned that if you change this value you'll need to change 28080 in a few
# spots in docker-compose.yml due to the nature of how this value can be set
# (Docker Compose doesn't support nested ENV vars).
#export CABLE_PORT=28080

# The Action Cable address that will be accessible over HTTP. In production
# you would typically have this reverse proxied to a sub-domain with nginx, in
# which case you would set something like: ws://cable.example.com
#
# This is one case where it defaults to a development value because it's not
# possible for me to know what domain name you'll be using.
#export ACTION_CABLE_FRONTEND_URL=ws://localhost:28080

# Comma separated list of RegExp origins to allow connections from for Action
# Cable. The values will be converted into a proper RegExp, so omit the / /.
#
# Examples:
# http:\/\/localhost*
# http:\/\/example.*,https:\/\/example.*
#export ACTION_CABLE_ALLOWED_REQUEST_ORIGINS=http:\/\/localhost*

# If this is set then Rails will serve files from public/ in production. You
# probably don't want this behavior unless you're testing prod mode locally,
# because nginx would typically serve static files.
#export RAILS_SERVE_STATIC_FILES=

# Should Docker restart your containers if they go down in unexpected ways?
#export DOCKER_RESTART_POLICY=unless-stopped
export DOCKER_RESTART_POLICY=no

# What health check test command do you want to run? In development, having it
# curl your web server will result in a lot of log spam, so setting it to
# /bin/true is an easy way to make the health check do basically nothing.
#export DOCKER_WEB_HEALTHCHECK_TEST=curl localhost:8000/up
export DOCKER_WEB_HEALTHCHECK_TEST=/bin/true

# What ip:port should be published back to the Docker host for the app server?
# If you're using Docker Toolbox or a custom VM you can't use 127.0.0.1. This
# is being overwritten in dev to be compatible with more dev environments.
#
# If you have a port conflict because something else is using 8000 then you
# can either stop that process or change 8000 to be something else.
#
# Use the default in production to avoid having puma directly accessible to
# the internet since it'll very likely be behind nginx or a load balancer.
#export DOCKER_WEB_PORT_FORWARD=127.0.0.1:8000
export DOCKER_WEB_PORT_FORWARD=127.0.0.1:3000

# This is the same as above except for Action Cable.
#export DOCKER_CABLE_PORT_FORWARD=127.0.0.1:28080
export DOCKER_CABLE_PORT_FORWARD=28080

# What volume path should be used? In dev we want to volume mount everything
# so that we can develop our code without rebuilding our Docker images.
#export DOCKER_WEB_VOLUME=./public:/app/public


export DOCKER_WEB_VOLUME=.:/app

# What CPU and memory constraints will be added to your services? When left at
# 0 they will happily use as much as needed.
# export DOCKER_POSTGRES_CPUS=0
# export DOCKER_POSTGRES_MEMORY=0
# export DOCKER_REDIS_CPUS=0
# export DOCKER_REDIS_MEMORY=0
# export DOCKER_WEB_CPUS=0
# export DOCKER_WEB_MEMORY=0
# export DOCKER_WORKER_CPUS=0
# export DOCKER_WORKER_MEMORY=0
# export DOCKER_CABLE_CPUS=0
# export DOCKER_CABLE_MEMORY=0
API_IMAGE_REPOSITORY=agroportal
API_IMAGE_TAG=stage
API_URL=http://localhost:9393
45 changes: 45 additions & 0 deletions .github/workflows/docker-dev-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Docker branch Images build

on:
push:
branches:
- development
- stage
- test

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

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

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

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

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4
with:
images: agroportal/ontoportal_web_ui

- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
context: .
platforms: linux/amd64,linux/arm64
build-args: |
RUBY_VERSION=2.7
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
52 changes: 52 additions & 0 deletions .github/workflows/tests-real-data.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
name: "Run remote API tests CI"

on:
push:
pull_request_target:
types: [ opened, reopened ]
env:
API_URL: ${{ secrets.API_URL }}
API_KEY: ${{ secrets.API_KEY }}
BIOMIXER_URL: ${{ secrets.BIOMIXER_URL }}
FAIRNESS_URL: ${{ secrets.FAIRNESS_URL }}
ANNOTATOR_URL: ${{ secrets.ANNOTATOR_URL }}
DB_HOST: 127.0.0.1
jobs:
test:
runs-on: ubuntu-latest
services:
mysql:
image: mysql:8.0
ports:
- "3306:3306"
env:
MYSQL_ROOT_PASSWORD: root
memcached:
image: memcached:1.6
ports:
- 11211:11211
steps:
- name: Checkout code
uses: actions/checkout@v3
# Add or replace dependency steps here
- name: Install Ruby and gems
uses: ruby/setup-ruby@v1
with:
ruby-version: 2.7.8
bundler-cache: true
# Add or replace database setup steps here
- name: set up config file
run: cp config/database.yml.sample config/database.yml
- name: Set up database schema
run: RAILS_ENV=test bin/rails db:setup
- name: Set up yarn
run: yarn install
# Add or replace test runners here
- name: Run tests
run: RAILS_ENV=test bin/rails test test/controllers/* -v
18 changes: 12 additions & 6 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,30 @@
# documentation.
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
name: "Ruby on Rails CI"
name: "Run local API tests CI"

on:
push:
pull_request_target:
types: [ opened, reopened ]
env:
API_URL: ${{ secrets.API_URL }}
API_KEY: ${{ secrets.API_KEY }}
API_URL: http://localhost:9393
REMOTE_API_KEY: 8b5b7825-538d-40e0-9e9e-5ab9274a9aeb
REMOTE_API_URL: https://data.bioontology.org
BIOMIXER_URL: ${{ secrets.BIOMIXER_URL }}
FAIRNESS_URL: ${{ secrets.FAIRNESS_URL }}
ANNOTATOR_URL: ${{ secrets.ANNOTATOR_URL }}
DB_HOST: 127.0.0.1
jobs:
test:
runs-on: ubuntu-latest
services:
mysql:
image: mysql:latest
image: mysql:8.0
ports:
- "3306:3306"
env:
MYSQL_ROOT_PASSWORD: 'bp_user'
MYSQL_ROOT_PASSWORD: root
memcached:
image: memcached:1.6
ports:
Expand All @@ -39,6 +41,10 @@ jobs:
with:
ruby-version: 2.7.8
bundler-cache: true

- name: Run OntoPortal API
run: bin/run_api -k ${{ env.REMOTE_API_KEY }} -r agroportal -t stage -s STY -u ${{ env.REMOTE_API_URL }}

# Add or replace database setup steps here
- name: set up config file
run: cp config/database.yml.sample config/database.yml
Expand All @@ -48,4 +54,4 @@ jobs:
run: yarn install
# Add or replace test runners here
- name: Run tests
run: RAILS_ENV=test bin/rails test -v
run: RAILS_ENV=test bin/rails test -v
79 changes: 42 additions & 37 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,50 +1,55 @@
FROM ruby:2.7.5-alpine AS app

# 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
WORKDIR /app

ARG UID=1000
ARG GID=1000

RUN apk add --no-cache \
build-base \
libxml2-dev \
libxslt-dev \
mariadb-dev \
git \
nodejs \
tzdata \
yarn \
less \
&& addgroup --gid ${GID} ruby \
&& adduser -u ${UID} -G ruby -D ruby \
&& chown ruby:ruby -R /app \
&& mkdir /node_modules \
&& chown ruby:ruby -R /node_modules /app

USER ruby

COPY --chown=ruby:ruby bin/ ./bin
RUN chmod 0755 bin/*

# Set production environment
ARG RAILS_ENV="production"
ARG BUNDLE_WITHOUT="development test"

ENV RAILS_ENV="${RAILS_ENV}" \
NODE_ENV="${NODE_ENV}" \
PATH="${PATH}:/home/ruby/.local/bin:/node_modules/.bin" \
USER="ruby" \
BUNDLE_PATH=/usr/local/bundle

COPY --chown=ruby:ruby Gemfile* ./
RUN bundle install --jobs "$(nproc)"
RUN gem install rails
ENV RAILS_LOG_TO_STDOUT="1" \
RAILS_SERVE_STATIC_FILES="true" \
RAILS_ENV="${RAILS_ENV}" \
BUNDLE_PATH=/usr/local/bundle \
BUNDLE_WITHOUT="${BUNDLE_WITHOUT}"

RUN gem update --system && \
gem install bundler

COPY Gemfile* .
RUN bundle install

RUN echo "--modules-folder /node_modules" > .yarnrc
COPY --chown=ruby:ruby package.json *yarn* ./
COPY package.json *yarn* ./
RUN yarn install

COPY . .

# Precompile bootsnap code for faster boot times
RUN bundle exec bootsnap precompile --gemfile app/ lib/

# Precompiling assets for production without requiring secret RAILS_MASTER_KEY
COPY ./config/database.yml.sample ./config/database.yml
RUN SECRET_KEY_BASE_DUMMY=1 RAILS_ENV=test bundle exec rails assets:precompile


ENV BINDING="0.0.0.0"
EXPOSE 3000

CMD ["sh"]
CMD ["bash"]
Loading

0 comments on commit 4f2f7d0

Please sign in to comment.