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

Containerize #203

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
3b928c9
Dockerize, Postgresize, Redisize, and Sidekiqize Tap
TomNaessens Jun 8, 2024
5dda46d
Correct Capfile
TomNaessens Jun 8, 2024
dbadae2
Correct Dockerfile
TomNaessens Jun 8, 2024
6925bce
Don't build development and test gems
TomNaessens Jun 8, 2024
ea6cb08
Get this thing to build on 3.3.2-slim
TomNaessens Jun 8, 2024
3820584
Add build github action
TomNaessens Jun 9, 2024
578b92c
Master, not main
TomNaessens Jun 9, 2024
965dd5c
Add labels and tags
TomNaessens Jun 9, 2024
1384d3a
Use git context
TomNaessens Jun 9, 2024
c63330e
Add SECRET_KEY_BASE secret
TomNaessens Jun 9, 2024
34ef515
Explicitly call it SECRET_KEY_BASE_DUMMY
TomNaessens Jun 9, 2024
7f5170f
Use dummy secret key base directly
TomNaessens Jun 9, 2024
1c112a8
Set registry to ghcr.io
TomNaessens Jun 9, 2024
80dd528
What if we remove the default label, will it then only push to GHCR?
TomNaessens Jun 9, 2024
39862ca
Remove registry, add cache to build workflow
TomNaessens Jun 9, 2024
9572634
Update docker-compose to pull from ghcr.io
TomNaessens Jun 9, 2024
381e6b3
Error: repository name must be lowercase
TomNaessens Jun 9, 2024
27a0bf9
Tag latest build as latest
TomNaessens Jun 9, 2024
af6b269
Do we need to publicly expose the db port?
TomNaessens Jun 9, 2024
35c5bc2
Pass .env file to docker-compose services
TomNaessens Jun 9, 2024
bdf84ae
Add rainbow for colored output on production
TomNaessens Jun 9, 2024
467bd95
Set pull_policy to always
TomNaessens Jun 9, 2024
dc470ab
Get rid of caching if podman can't handle it
TomNaessens Jun 9, 2024
22ab368
Stop exposing redis port
TomNaessens Jun 9, 2024
ff1b6d4
use alpine
xerbalind Jun 9, 2024
95b5c94
test building on this branch
xerbalind Jun 9, 2024
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
43 changes: 43 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Build

on:
push:
branches:
- 'master'
- 'tom-containerize'

env:
REGISTRY: ghcr.io

jobs:
docker:
runs-on: ubuntu-latest
steps:
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
ghcr.io/ZeusWPI/Tap
tags: |
type=raw,value=latest,enable={{is_default_branch}}
type=sha
flavor: |
latest=auto

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

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v5
with:
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
33 changes: 16 additions & 17 deletions .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,31 @@ on:
jobs:
test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
bundler-cache: true

- run: RAILS_ENV=test bundle exec rake db:create
- run: RAILS_ENV=test bundle exec rake db:schema:load
- run: bundle exec rake
env:
COVERALLS_REPO_TOKEN : ${{ secrets.COVERALLS_REPO_TOKEN }}
- uses: actions/checkout@v4

- name: Build the stack
run: docker-compose up -d db-test

- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
bundler-cache: true

- run: RAILS_ENV=test bundle exec rake db:create
- run: RAILS_ENV=test bundle exec rake db:schema:load
- run: bundle exec rake

lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
bundler-cache: true

- name: Lint with rubocop
env:
RAILS_ENV: "test"
run: |
bundle exec rubocop -c .rubocop.yml
bundle exec rubocop -c .rubocop.yml
29 changes: 29 additions & 0 deletions .irbrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# frozen_string_literal: true

require "rainbow/refinement"

if defined? Rails
using Rainbow

env_prompt = if Rails.env.development?
Rails.env[0..2].green
elsif Rails.env.production?
Rainbow(Rails.env.upcase).black.background(:red).bright.bold
else
Rails.env.magenta
end

prompt = "[%n]#{env_prompt}(#{Rainbow('%m').yellow}):%i"

IRB.conf[:PROMPT] ||= {}
IRB.conf[:PROMPT][:RAILS] = {
PROMPT_I: "#{prompt}> ",
PROMPT_S: "#{prompt}%l ",
PROMPT_C: "#{prompt}? ",
RETURN: "=> %s\n"
}

IRB.conf[:PROMPT_MODE] = :RAILS
end

IRB.conf[:USE_AUTOCOMPLETE] = ENV["IRB_USE_AUTOCOMPLETE"] == "true"
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.3.1
3.3.2
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
ruby 3.3.1
ruby 3.3.2
yarn 1.22.19
nodejs 16.15.0
7 changes: 4 additions & 3 deletions Capfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ require "capistrano/deploy"
require "capistrano/scm/git"
install_plugin Capistrano::SCM::Git

require "capistrano/rails"
require "capistrano/asdf"
require "capistrano/docker"
require "capistrano/docker/compose/logs"
require "capistrano/docker/compose/migration"

# Loads custom tasks from `lib/capistrano/tasks' if you have any defined.
Dir.glob("lib/capistrano/tasks/*.cap").each { |r| import r }
Dir.glob("lib/capistrano/tasks/*.rake").each { |r| import r }
75 changes: 18 additions & 57 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,67 +1,28 @@
##################
### Base image ###
##################
FROM ruby:3.0.2-alpine as base
FROM ruby:3.3.2-slim

# Install the required packages for building
# Delete APK cache at the end (for smaller production images)
RUN apk update && \
apk add --virtual build-dependencies build-base && \
apk add shared-mime-info mariadb-dev sqlite-dev nodejs tzdata imagemagick && \
rm -rf /var/cache/apk/*
ENV RAILS_ENV=production

# Create a working directory
WORKDIR /tap
RUN apt update && apt install -y git libpq-dev build-essential gpg curl

# Copy the gemfile to the working directory
COPY Gemfile Gemfile
COPY Gemfile.lock Gemfile.lock
WORKDIR /app

# Install dependencies
# Use BuildKit cache for caching dependencies
RUN --mount=type=cache,target=vendor/cache bundle install
COPY ./Gemfile ./Gemfile.lock /app/

# Copy all of the .gem files needed to run the application into the vendor/cache directory.
# In the future, when running [bundle install(1)][bundle-install], use the gems in the cache in preference to the ones on rubygems.org
RUN bundle cache
RUN gem install bundler
RUN bundle config set without 'development test'
RUN bundle install

########################
### Production image ###
########################
FROM base as production
RUN curl -fsSL https://deb.nodesource.com/setup_16.x | bash -
RUN apt install -y nodejs
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
RUN apt update && apt install -y yarn

# Copy the sourcecode
COPY . .
COPY ./package.json ./yarn.lock /app/
RUN yarn install

# Run rails in production mode
ENV RAILS_ENV production
COPY . /app

# Expose port 80
# This is the main port for the application
EXPOSE 80
RUN SECRET_KEY_BASE="dummy_secret_key_base" bundle exec rails assets:precompile

# Pre-compile assets
RUN rake assets:precompile

# Docker Entrypoint
# Will be started when the container is started
ENTRYPOINT sh docker-start.sh

#########################
### Development image ###
#########################
FROM base as development

# Copy the sourcecode
COPY . .

# Run rails in production mode
ENV RAILS_ENV development

# Expose port 80
# This is the main port for the application
EXPOSE 80

# Docker Entrypoint
# Will be started when the container is started
CMD sh docker-start.sh
CMD bundle exec rails s -b 0.0.0.0
29 changes: 10 additions & 19 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,10 @@ gem "cancancan", "~> 3.3"
# Default avatar for users
gem "identicon", "0.0.5"

# Run stuff in the background
gem "daemons", "~> 1.4"
gem "delayed_job", "~> 4.1"
gem "delayed_job_active_record"

# Needed for deployment somehow
gem "bcrypt_pbkdf"
gem "ed25519"

# Ruby debugger
gem "byebug"

gem "httparty", "~> 0.20.0"

# windows support (linux timezone directory is used in the project)
Expand All @@ -81,10 +73,14 @@ gem "sentry-rails"
gem "sentry-ruby"
gem "stackprof"

# Production dependencies
group :production do
gem "mysql2", "~> 0.5.3"
end
# Run stuff in background
gem "sidekiq", "~> 7.0"

# Use PostgreSQL as the database for Active Record
gem "pg"

# Rainbow for colored output in irb, even in production
gem "rainbow"

# Test dependencies
group :test do
Expand All @@ -94,20 +90,15 @@ end

# Development dependencies
group :development do
# Use sqlite3 as the database for Active Record
gem "sqlite3", "~> 1.4"

# Annotates Rails/ActiveRecord Models, routes, fixtures, and others based on the database schema.
gem "annotate", "~> 3.1"

# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem "spring", "~> 3.0"

# Deployment
gem "capistrano"
gem "capistrano-asdf"
gem "capistrano-passenger"
gem "capistrano-rails"
gem "capistrano", "~> 3.17"
gem "capistrano-docker", github: "TomNaessens/capistrano-docker"

# Linting
gem "rubocop", "~> 1.30"
Expand Down
Loading