Replaces complex Dockerfiles by Earthly file 馃帀

parent 019fae80
# ~~~~ Image base ~~~~
FROM ruby:2.4.1-slim
MAINTAINER zedtux, [email protected]
ENV DEBIAN_FRONTEND noninteractive
# ~~~~ System locales ~~~~
RUN apt-get update && apt-get install -y locales && \
dpkg-reconfigure locales && \
locale-gen C.UTF-8 && \
/usr/sbin/update-locale LANG=C.UTF-8 && \
echo 'en_US.UTF-8 UTF-8' >> /etc/locale.gen && \
locale-gen
# Set default locale for the environment
ENV LC_ALL C.UTF-8
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US.UTF-8
ENV APP_HOME /application
# ~~~~ User and folders ~~~~
RUN useradd -ms /bin/bash brewformulas && \
mkdir /bundle $APP_HOME && \
chown -R brewformulas:brewformulas $APP_HOME && \
chown -R brewformulas:users /usr/local/
# ~~~~ Application dependencies ~~~~
RUN apt-get install -y libpq-dev \
build-essential \
nodejs \
git
# ~~~~ Bundler ~~~~
RUN gem install bundler
WORKDIR $APP_HOME
COPY Gemfile* $APP_HOME/
# ~~~~ Install Rails application gems ~~~~
ENV BUNDLE_GEMFILE=$APP_HOME/Gemfile \
BUNDLE_JOBS=8 \
BUNDLE_PATH=/bundle
RUN gem install rubygems-update --no-ri --no-rdoc --version 2.7.0 && \
update_rubygems && \
bundle install --without production
# ~~~~ Import application ~~~~
COPY . $APP_HOME
RUN bundle exec rake assets:precompile RAILS_ENV=production
RUN chown -R brewformulas:brewformulas $APP_HOME && \
chown -R brewformulas:users /bundle && \
chown -R brewformulas:users /usr/local/bundle
USER brewformulas
# This image inherits from the Production version and installs the required
# libraries in order to run the tests.
#
# This will allow then to push the production image (and not this image) which
# will not have all the stuff for running the tests.
#
FROM zedtux/brewformulas.org:latest
MAINTAINER zedtux, [email protected]
USER root
ENV RAILS_ENV test
RUN apt-get update && apt-get install -y make gcc g++
USER brewformulas
RUN bundle config --delete without && \
bundle install --jobs 8
# Brewformulas.org web application Docker image
# ~~~~ Image base ~~~~
FROM ruby:2.4.1-slim
MAINTAINER zedtux, [email protected]
# Set default locale for the environment
ENV RUNNING_IN_DOCKER true
ENV APP_HOME /application
ENV LC_ALL C.UTF-8
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US.UTF-8
# ~~~~ Running user ~~~~
RUN useradd -ms /bin/bash brewformulas && \
mkdir -p $APP_HOME
# ~~~~ Sources Preparation ~~~~
WORKDIR $APP_HOME
ADD . $APP_HOME
# ~~~~ System Dependencies ~~~~
RUN apt-get update && \
apt-get install -y locales \
ca-certificates \
libpq-dev \
git \
make \
gcc \
g++ \
nodejs && \
dpkg-reconfigure locales && \
locale-gen C.UTF-8 && \
/usr/sbin/update-locale LANG=C.UTF-8 && \
echo 'en_US.UTF-8 UTF-8' >> /etc/locale.gen && \
locale-gen && \
gem install rubygems-update --no-ri --no-rdoc --version 2.7.0 && \
update_rubygems && \
gem install bundler --no-ri --no-rdoc && \
bundle install --without development test --jobs 8 && \
bundle exec rake assets:precompile RAILS_ENV=production && \
chown -R brewformulas:brewformulas $APP_HOME && \
chown -R brewformulas:brewformulas /usr/local/bundle && \
apt-get remove --purge -y make gcc g++ && \
apt-get autoremove -y && \
apt-get clean -y && \
rm -f tmp/pids/*
USER brewformulas
EXPOSE 3000
ENTRYPOINT ["bundle", "exec"]
CMD ["bin/rails server -b 0.0.0.0"]
FROM ruby:2.6-slim-buster
WORKDIR /application
# `deps` installs all the system libraries required by the gems in order
# to install them all.
# Finally it creates a temporary image used as a base image later.
deps:
RUN apt-get update \
&& apt-get install -y libpq-dev \
build-essential \
nodejs \
git
SAVE IMAGE
# `gems` installs all the gems from the Gemfile.lock for a production usage.
# Finally it creates a temporary image used as a base image later.
gems:
FROM +deps
ENV BUNDLE_GEMFILE=/application/Gemfile
ENV BUNDLE_JOBS=8
ENV BUNDLE_PATH=/bundle
COPY Gemfile* ./
RUN gem install rubygems-update \
&& update_rubygems \
&& gem install bundler:1.16.0 \
&& bundle install --without development test
SAVE IMAGE
# `assets` runs the Rails assets:precompile task and create an artifact from it
# used in the `prod` target.
assets:
FROM +gems
ENV RAILS_ENV production
COPY . /application
RUN bundle exec rake assets:precompile RAILS_ENV=production
SAVE ARTIFACT public/assets assets
# `prod` builds the production image of the project which means precompiling
# the projet assets.
# Finally it creates the Docker image used in order to run the project.
prod:
FROM +gems
ENV RAILS_ENV production
RUN useradd -ms /bin/bash brewformulas
COPY . /application
COPY +assets/assets public/assets
RUN chown -R brewformulas:users /application
EXPOSE 3000
ENTRYPOINT ["bundle", "exec"]
CMD ["bin/rails server -b 0.0.0.0"]
SAVE IMAGE zedtux/brewformulas.org:latest
# `ci` is based on the production image, in order to keep an environmnet as
# close as possible with production when running the tests.
# Nonetheless it install additionnal gems used to run the tests.
ci:
FROM +prod
ENV RAILS_ENV test
RUN bundle install --gemfile=/application/Gemfile \
--jobs=8 \
--path=/bundle \
--without development
SAVE IMAGE zedtux/brewformulas.org:latest-ci
# `dev` is based on the production image, in order to keep an environmnet as
# close as possible with produciton and then installs all the other gems for
# developing the project.
# The final image is used by the local docker-compose.yml file.
dev:
FROM +prod
ENV RAILS_ENV development
RUN bundle config --delete without
RUN bundle install --gemfile=/application/Gemfile \
--jobs=8 \
--path=/bundle
# Allow adding/removing/updating gems
RUN chown -R brewformulas:users /bundle
SAVE IMAGE zedtux/brewformulas.org:latest-dev
......@@ -53,6 +53,8 @@ group :development do
gem 'better_errors'
gem 'binding_of_caller'
gem 'listen', '3.1.5'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
......
......@@ -361,6 +361,7 @@ DEPENDENCIES
jquery-infinite-pages (~> 0.2.0)
jquery-rails (~> 4.3.3)
kaminari (~> 1.1.1)
listen (= 3.1.5)
metamagic (~> 3.1.7)
octicons_helper (~> 7.3.0)
opbeat (~> 3.0.9)
......
......@@ -17,7 +17,36 @@ It is a Rails 5 and Ruby 2 application using Twitter bootstrap 4 for the UI and
The aim of http://brewformulas.org/ is to provide a fast and simple web site to search for a [Homebrew](https://github.com/Homebrew/homebrew) formula.
The website is under heavy development so feel free to check regularly in order to discover new features.
This project is something I'm doing in order to test new things like gems, Docker, and more.
# Usage
This section explain you how to run this project.
## Prerequires
* You first need to [install Docker](https://docs.docker.com/get-docker/).
* You also need to [install Earthly](https://docs.earthly.dev/installation)
## Build the Docker image
This project has 3 targets:
* prod
* ci
* dev
Depending on your usecase, you will build the target that you need:
```
earth +dev
```
Let's say you now want to run it locally:
1. In a first terminal, run `docker-compose up`
2. After the app is started, run `docker-compose exec web bundle exec rake db:create db:migrate`
3. Open http://localhost:3000
# Documentation
......
class CreateHomebrewFormulasTable < ActiveRecord::Migration
class CreateHomebrewFormulasTable < ActiveRecord::Migration[4.2]
def change
create_table :homebrew_formulas do |t|
t.string :name, null: false
......
class AddTouchedOnColumnToHomebrewFormulasTable < ActiveRecord::Migration
class AddTouchedOnColumnToHomebrewFormulasTable < ActiveRecord::Migration[4.2]
def change
add_column :homebrew_formulas, :touched_on, :date
execute "UPDATE homebrew_formulas SET touched_on = '#{Date.yesterday}'"
......
class AddFilenameColumnToHomebrewFormulasTable < ActiveRecord::Migration
class AddFilenameColumnToHomebrewFormulasTable < ActiveRecord::Migration[4.2]
def change
# We are going to use the filename as primary key
# so we can remove all and redo the import
......
class AddDescriptionAutomaticColumnToHomebrewFormulasTable < ActiveRecord::Migration
class AddDescriptionAutomaticColumnToHomebrewFormulasTable < ActiveRecord::Migration[4.2]
def change
add_column :homebrew_formulas, :description_automatic, :boolean, default: false
end
......
class CreateHomebrewFormulasFormulasTable < ActiveRecord::Migration
class CreateHomebrewFormulasFormulasTable < ActiveRecord::Migration[4.2]
def change
create_table :dependencies_formulas, id: false do |t|
t.references :dependency
......
class ReplaceDependenciesFormulasTableByHomebrewFormulaDependenciesTable < ActiveRecord::Migration
class ReplaceDependenciesFormulasTableByHomebrewFormulaDependenciesTable < ActiveRecord::Migration[4.2]
def change
drop_table :dependencies_formulas
......
class CreateHomebrewFormulaConflictsTable < ActiveRecord::Migration
class CreateHomebrewFormulaConflictsTable < ActiveRecord::Migration[4.2]
def change
create_table :homebrew_formula_conflicts do |t|
t.integer :formula_id, null: false
......
class AddExternalColumnToHomebrewFormulasTable < ActiveRecord::Migration
class AddExternalColumnToHomebrewFormulasTable < ActiveRecord::Migration[4.2]
def change
add_column :homebrew_formulas, :external, :boolean, default: false, null: false
add_index :homebrew_formulas, :external
......
class CreateImportsTable < ActiveRecord::Migration
class CreateImportsTable < ActiveRecord::Migration[4.2]
def change
create_table :imports do |t|
t.boolean :success
......
......@@ -2,7 +2,9 @@ class AddsYearHitsColumnToTheHomebrewFormulasTable < ActiveRecord::Migration[5.1
def change
add_column :homebrew_formulas, :yearly_hits, :string
Homebrew::Formula.update_all(yearly_hits: [0,0,0,0,0,0,0,0,0,0,0])
Homebrew::Formula.all.each do |formula|
formula.update(yearly_hits: [0,0,0,0,0,0,0,0,0,0,0])
end
change_column_null :homebrew_formulas, :yearly_hits, false
end
......
......@@ -15,7 +15,7 @@ ActiveRecord::Schema.define(version: 20170601090528) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
create_table "homebrew_formula_conflicts", force: :cascade do |t|
create_table "homebrew_formula_conflicts", id: :serial, force: :cascade do |t|
t.integer "formula_id", null: false
t.integer "conflict_id", null: false
t.datetime "created_at"
......@@ -23,7 +23,7 @@ ActiveRecord::Schema.define(version: 20170601090528) do
t.index ["formula_id", "conflict_id"], name: "homebrew_formula_conflicts_uniqueness", unique: true
end
create_table "homebrew_formula_dependencies", force: :cascade do |t|
create_table "homebrew_formula_dependencies", id: :serial, force: :cascade do |t|
t.integer "formula_id", null: false
t.integer "dependency_id", null: false
t.datetime "created_at"
......@@ -31,7 +31,7 @@ ActiveRecord::Schema.define(version: 20170601090528) do
t.index ["formula_id", "dependency_id"], name: "homebrew_formula_dependencies_uniqueness", unique: true
end
create_table "homebrew_formulas", force: :cascade do |t|
create_table "homebrew_formulas", id: :serial, force: :cascade do |t|
t.string "name", null: false
t.string "version"
t.string "homepage"
......@@ -47,7 +47,7 @@ ActiveRecord::Schema.define(version: 20170601090528) do
t.index ["filename"], name: "index_homebrew_formulas_on_filename"
end
create_table "imports", force: :cascade do |t|
create_table "imports", id: :serial, force: :cascade do |t|
t.boolean "success"
t.text "message"
t.datetime "ended_at"
......
......@@ -9,12 +9,12 @@ services:
image: memcached:1.5.3-alpine
bundle:
image: zedtux/brewformulas.org
image: zedtux/brewformulas.org:latest-dev
command: echo Bundler data container
volumes:
- /bundle
workers:
image: zedtux/brewformulas.org
image: zedtux/brewformulas.org:latest-dev
command: bundle exec sidekiq
links:
- postgres:database
......@@ -29,7 +29,7 @@ services:
volumes_from:
- bundle
web:
image: zedtux/brewformulas.org
image: zedtux/brewformulas.org:latest-dev
build: .
command: bin/rails server -b 0.0.0.0 -p 3000
links:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment