Skip to content

Commit

Permalink
Github actions & docker support (#46)
Browse files Browse the repository at this point in the history
* Add dockerfile

* Add workflow

* GITHUB_* not allowed

* lower case

* push

* add sourde

* remove images asset

* RAILS_LOG_LEVEL

* Truncate instead of delete

* Correct branch for workflows

* Update bundler version

attempt 1

* Update build.sh

* Update build-and-publish.yml
  • Loading branch information
thekeenant authored Nov 27, 2023
1 parent fa5452e commit 3350f2d
Show file tree
Hide file tree
Showing 18 changed files with 112 additions and 44 deletions.
12 changes: 12 additions & 0 deletions .dockerfiles/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash
# Install dependencies.
export DEBIAN_FRONTEND=noninteractive
apt-get update
apt-get install -y \
build-essential \
ruby-full \
default-libmysqlclient-dev \
tzdata \
nodejs
gem install bundler -v 2.3.26
bundle install
4 changes: 4 additions & 0 deletions .dockerfiles/run-api.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
rm tmp/pids/server.pid -rf
bundle exec rake assets:precompile
rails server
2 changes: 2 additions & 0 deletions .dockerfiles/run-migrations.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
rake db:migrate
2 changes: 2 additions & 0 deletions .dockerfiles/run-seed.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
rake seed -- --path=/seed
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.env
16 changes: 15 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
GITHUB_KEY=
GITHUB_SECRET=

SECRET_KEY_BASE=
ELASTICSEARCH_URL=http://localhost:9200

ELASTICSEARCH_URL=http://localhost:9200

DATABASE_USERNAME=
DATABASE_PASSWORD=
DATABASE_HOST=127.0.0.1
DATABASE_PORT=3306
DATABASE_NAME=

DEV_DATABASE_NAME=
TEST_DATABASE_NAME=

RAILS_LOG_TO_STDOUT=
RAILS_LOG_LEVEL=info
30 changes: 30 additions & 0 deletions .github/workflows/build-and-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Build and Publish
on:
push:
branches:
- main
pull_request:
jobs:
build-and-push-docker-image:
name: Build Docker image and publish
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
# - name: Set up Docker Buildx
# id: buildx
# uses: docker/setup-buildx-action@v2
- name: Login to Github Packages
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ secrets.PUBLISHING_GITHUB_USERNAME }}
password: ${{ secrets.PUBLISHING_GITHUB_TOKEN }}
- name: Build image and push to Docker Hub and GitHub Container Registry
uses: docker/build-push-action@v2
with:
context: ./
tags: |
ghcr.io/madgrades/api.madgrades.com:latest
# push: true
push: ${{ github.ref == 'refs/heads/main' }}
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
.idea
database.yml
.env
public/assets

Expand All @@ -16,3 +15,6 @@ public/assets
/yarn-error.log

.byebug_history

# Ignore master key for decrypting credentials and more.
/config/master.key
11 changes: 11 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM ubuntu:bionic AS build
WORKDIR /build
COPY . .
RUN .dockerfiles/build.sh

FROM build AS app
LABEL org.opencontainers.image.source https://github.com/Madgrades/api.madgrades.com
WORKDIR /app
COPY --from=build /build .
# Default to running app. This can be overriden from docker cli.
CMD .dockerfiles/run-app.sh
3 changes: 1 addition & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ end

gem 'rack-throttle'
gem 'rufus-scheduler'
gem 'dotenv'
gem 'dotenv-rails'
gem 'dotenv-rails', require: 'dotenv/rails-now'
gem 'rails-html-sanitizer'

# api auth
Expand Down
1 change: 0 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,6 @@ PLATFORMS
DEPENDENCIES
byebug
capybara (~> 2.13)
dotenv
dotenv-rails
font-awesome-rails
jbuilder
Expand Down
1 change: 0 additions & 1 deletion app/assets/config/manifest.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
//= link_tree ../images
//= link_directory ../javascripts .js
//= link_directory ../stylesheets .css
20 changes: 20 additions & 0 deletions config/database.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
default: &default
adapter: mysql2
encoding: utf8
pool: 10
username: <%= ENV['DATABASE_USERNAME'] %>
password: <%= ENV['DATABASE_PASSWORD'] %>
host: <%= ENV['DATABASE_HOST'] %>
port: <%= ENV['DATABASE_PORT'] %>

development:
<<: *default
database: <%= ENV['DEV_DATABASE_NAME'] %>

test:
<<: *default
database: <%= ENV['TEST_DATABASE_NAME'] %>

production:
<<: *default
database: <%= ENV['DATABASE_NAME'] %>
21 changes: 0 additions & 21 deletions config/database.yml.example

This file was deleted.

2 changes: 1 addition & 1 deletion config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@

# Use the lowest log level to ensure availability of diagnostic information
# when problems arise.
config.log_level = :debug
config.log_level = ENV.fetch("RAILS_LOG_LEVEL", "info").downcase.strip.to_sym

# Prepend all log lines with the following tags.
config.log_tags = [ :request_id ]
Expand Down
3 changes: 0 additions & 3 deletions config/puma/production.rb

This file was deleted.

3 changes: 0 additions & 3 deletions drop_migrate.sh

This file was deleted.

20 changes: 10 additions & 10 deletions lib/tasks/seed.rake
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ namespace :seed do
end

puts 'Deleting base tables (this may take a while)...'
CourseOffering.delete_all
Course.delete_all
GradeDistribution.delete_all
Instructor.delete_all
Room.delete_all
Schedule.delete_all
Section.delete_all
SubjectMembership.delete_all
Subject.delete_all
Teaching.delete_all
ActiveRecord::Base.connection.truncate(CourseOffering.table_name)
ActiveRecord::Base.connection.truncate(Course.table_name)
ActiveRecord::Base.connection.truncate(GradeDistribution.table_name)
ActiveRecord::Base.connection.truncate(Instructor.table_name)
ActiveRecord::Base.connection.truncate(Room.table_name)
ActiveRecord::Base.connection.truncate(Schedule.table_name)
ActiveRecord::Base.connection.truncate(Section.table_name)
ActiveRecord::Base.connection.truncate(SubjectMembership.table_name)
ActiveRecord::Base.connection.truncate(Subject.table_name)
ActiveRecord::Base.connection.truncate(Teaching.table_name)

glob = Dir.glob("#{options[:path]}/*.sql")
puts "Seeding tables from: #{options[:path]}/*.sql (#{glob})"
Expand Down

0 comments on commit 3350f2d

Please sign in to comment.