Skip to content

Commit

Permalink
Using pg in yai branch, released new version
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric-Guo committed May 23, 2024
1 parent d3306c6 commit c2de129
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 33 deletions.
8 changes: 8 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
image: circleci/ruby:3.0.3-node-browsers

variables:
POSTGRES_HOST: postgres
POSTGRES_DB: pagila_test
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
CACHE_FALLBACK_KEY: "$CI_COMMIT_REF_SLUG"

before_script:
Expand All @@ -15,6 +19,8 @@ stages:
- deploy

test:
services:
- postgres:12.9
stage: test
cache:
- key:
Expand All @@ -27,6 +33,8 @@ test:
- yarn.lock
paths:
- ".yarn-cache/"
variables:
DATABASE_URL: postgresql://postgres:postgres@postgres:5432/$POSTGRES_DB
script:
- bundle install -j $(nproc)
- yarn install --cache-folder .yarn-cache
Expand Down
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ ENV RAILS_ENV="production" \
BUNDLE_PATH="/usr/local/bundle" \
BUNDLE_WITHOUT="development"

# Install libpq to access pg
RUN apt-get update && apt-get install -y libpq-dev

# Throw-away build stage to reduce size of final image
FROM base as build
Expand Down
3 changes: 1 addition & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ gem 'rails-i18n'
# released.
gem 'mail', '= 2.8.1'

# Use sqlite3 as the database for Active Record
gem 'sqlite3', '~> 1.7'
gem 'pg'
# Use Puma as the app server
gem 'puma'
# Use jquery as the JavaScript library
Expand Down
9 changes: 2 additions & 7 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ GEM
racc (~> 1.4)
orm_adapter (0.5.0)
pagy (8.4.0)
pg (1.5.6)
psych (5.1.2)
stringio
public_suffix (5.0.5)
Expand Down Expand Up @@ -380,12 +381,6 @@ GEM
actionpack (>= 5.2)
activesupport (>= 5.2)
sprockets (>= 3.0.0)
sqlite3 (1.7.3-aarch64-linux)
sqlite3 (1.7.3-arm-linux)
sqlite3 (1.7.3-arm64-darwin)
sqlite3 (1.7.3-x86-linux)
sqlite3 (1.7.3-x86_64-darwin)
sqlite3 (1.7.3-x86_64-linux)
sshkit (1.22.2)
base64
mutex_m
Expand Down Expand Up @@ -475,6 +470,7 @@ DEPENDENCIES
minitest
minitest-ci
pagy
pg
puma
pundit
rails (~> 7.1.2)
Expand All @@ -485,7 +481,6 @@ DEPENDENCIES
simplecov
spring
sprockets
sqlite3 (~> 1.7)
terser
turbolinks
tzinfo-data
Expand Down
25 changes: 19 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,32 @@ rm config/credentials.yml.enc
export EDITOR=vim
# paste credentials.yml.sample or skip
bin/rails credentials:edit
bin/rails db:create
bin/rails test:all
```

# Build & Run in docker mode
# Create postgresql db user in Mac

```bash
docker build --tag ericguo/oauth2id:main .
# or `docker pull ericguo/oauth2id:main` to using existing images
docker run -p 3000:3000 -d --restart always --name oauth2id --env RAILS_MASTER_KEY=YourMasterKey -v ./storage:/rails/storage ericguo/oauth2id:main
sudo su - postgres
createuser oauth2id_prod
psql -d postgres
ALTER ROLE oauth2id_prod LOGIN;
ALTER USER oauth2id_prod PASSWORD 'oauth2id_prod';
CREATE DATABASE oauth2id_prod WITH ENCODING='UTF8' OWNER=oauth2id_prod;
logout
```

# Build & Run in docker mode in OrbStack

```bash
docker build --tag ericguo/oauth2id:yai .
# or `docker pull ericguo/oauth2id:yai` to using existing images
docker run -p 3000:3000 -d --restart always --name oauth2id-yai --env RAILS_MASTER_KEY=YourMasterKey --env OAUTH2ID_DB_NAME=oauth2id_prod --env OAUTH2ID_DB_HOST=host.docker.internal --env OAUTH2ID_DB_USERNAME=oauth2id_prod --env OAUTH2ID_DB_PASSWORD=oauth2id_prod -v ./storage:/rails/storage ericguo/oauth2id:yai
# If can not start in above, do the debug.
docker run --env RAILS_MASTER_KEY=YourMasterKey -v ./storage:/rails/storage -it ericguo/oauth2id:main bash
docker run --env RAILS_MASTER_KEY=YourMasterKey --env OAUTH2ID_DB_NAME=oauth2id_prod --env OAUTH2ID_DB_HOST=host.docker.internal --env OAUTH2ID_DB_USERNAME=oauth2id_prod --env OAUTH2ID_DB_PASSWORD=oauth2id_prod -v ./storage:/rails/storage -it ericguo/oauth2id:yai bash
# After success, push manually.
docker push ericguo/oauth2id:main
docker push ericguo/oauth2id:yai
```

# Dev env setup
Expand Down
13 changes: 9 additions & 4 deletions config/database.yml.sample
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
---
default: &default
adapter: sqlite3
adapter: postgresql
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
timeout: 5000

development:
primary:
<<: *default
database: storage/oauth2id_dev.sqlite3
database: <%= ENV.fetch("OAUTH2ID_DEV_DB_NAME") { 'oauth2id_dev' } %>

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
primary:
<<: *default
database: storage/oauth2id_test.sqlite3
database: <%= ENV.fetch("OAUTH2ID_TEST_DB_NAME") { 'oauth2id_test' } %>
username: <%= ENV.fetch("OAUTH2ID_DB_USERNAME") { '' } %>
host: <%= ENV.fetch("OAUTH2ID_DB_HOST") { '' } %>

production:
primary:
<<: *default
database: storage/oauth2id_prod.sqlite3
database: <%= ENV.fetch("OAUTH2ID_DB_NAME") { 'oauth2id_prod' } %>
username: <%= ENV.fetch("OAUTH2ID_DB_USERNAME") { '' } %>
password: <%= ENV.fetch("OAUTH2ID_DB_PASSWORD") { '' } %>
host: <%= ENV.fetch("OAUTH2ID_DB_HOST") { '' } %>
31 changes: 17 additions & 14 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.0].define(version: 2024_01_05_132232) do
ActiveRecord::Schema[7.1].define(version: 2024_01_05_132232) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"

create_table "allowlisted_jwts", force: :cascade do |t|
t.string "jti", null: false
t.string "aud", null: false
t.datetime "exp", precision: nil, null: false
t.integer "user_id", null: false
t.bigint "user_id", null: false
t.index ["jti"], name: "index_allowlisted_jwts_on_jti", unique: true
t.index ["user_id"], name: "index_allowlisted_jwts_on_user_id"
end
Expand All @@ -30,8 +33,8 @@
end

create_table "department_users", force: :cascade do |t|
t.integer "department_id", null: false
t.integer "user_id", null: false
t.bigint "department_id", null: false
t.bigint "user_id", null: false
t.datetime "created_at", precision: nil, null: false
t.datetime "updated_at", precision: nil, null: false
t.index ["department_id"], name: "index_department_users_on_department_id"
Expand All @@ -48,8 +51,8 @@
end

create_table "oauth_access_grants", force: :cascade do |t|
t.integer "resource_owner_id", null: false
t.integer "application_id", null: false
t.bigint "resource_owner_id", null: false
t.bigint "application_id", null: false
t.string "token", null: false
t.integer "expires_in", null: false
t.text "redirect_uri", null: false
Expand All @@ -64,8 +67,8 @@
end

create_table "oauth_access_tokens", force: :cascade do |t|
t.integer "resource_owner_id"
t.integer "application_id"
t.bigint "resource_owner_id"
t.bigint "application_id"
t.string "token", null: false
t.string "refresh_token"
t.integer "expires_in"
Expand Down Expand Up @@ -111,8 +114,8 @@
end

create_table "position_users", force: :cascade do |t|
t.integer "position_id", null: false
t.integer "user_id", null: false
t.bigint "position_id", null: false
t.bigint "user_id", null: false
t.boolean "main_position", default: false
t.datetime "created_at", precision: nil, null: false
t.datetime "updated_at", precision: nil, null: false
Expand All @@ -128,7 +131,7 @@
end

create_table "profiles", force: :cascade do |t|
t.integer "user_id"
t.bigint "user_id"
t.string "title"
t.boolean "gender"
t.string "phone"
Expand All @@ -140,8 +143,8 @@
end

create_table "user_allowed_applications", force: :cascade do |t|
t.integer "user_id"
t.integer "oauth_application_id"
t.bigint "user_id"
t.bigint "oauth_application_id"
t.boolean "enable", default: true
t.datetime "created_at", precision: nil, null: false
t.datetime "updated_at", precision: nil, null: false
Expand All @@ -150,7 +153,7 @@
end

create_table "user_sign_in_histories", force: :cascade do |t|
t.integer "user_id"
t.bigint "user_id"
t.datetime "sign_in_at", precision: nil
t.text "user_agent"
t.string "sign_in_ip"
Expand Down

0 comments on commit c2de129

Please sign in to comment.