Skip to content

Commit

Permalink
Use internal SQLite3 database (#67)
Browse files Browse the repository at this point in the history
* Removed postgres service

* Replace postgres config with sqlite3

* Fixed failing migrations

* fix ILIKE issue in SQLite

* generate values

* loading data with indexes, next is start searching

* state search done, new method alpharize to convert accented characters to alphanumeric

* finish fixing zip code searches

* go to lunch, commit to continue

* fix specs

* delete comments and fix format

* description about populate db

* items per page flexibility added

* add to devcontainer sqlite extension

fix instruction in readme file

download the new zip codes database

add to rake task, the loadev task, to load locally the db

* change the port to 80 to avoid aditional azure config

add dockerignore exception to /tmp/pids folder

* keep the pids folder, because it causes a failure

* fix gitignore issue

* fix deletion of pids folder that causes a issue when build and deploy

* add ci/cd to dockerhub/azure

* Update CI & CD workflow to trigger on workflow_dispatch event for test in PR

* test pr flow

* change to main

* fix codeclimate issue try 1

* try 2

* try 3

* try 4

* try 5

* try 6

* try 6

* try 7

* try 8

---------

Co-authored-by: Alexandro Castillo <wikitelmex@gmail.com>
Co-authored-by: Alex Castillo <149025926+dvlex@users.noreply.github.com>
Co-authored-by: Alex <alex@lexdrel.com>
  • Loading branch information
4 people committed May 2, 2024
1 parent bf564a9 commit a9fa5af
Show file tree
Hide file tree
Showing 51 changed files with 168,158 additions and 13,221 deletions.
3 changes: 2 additions & 1 deletion .codeclimate.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
engines:
plugins:
brakeman:
enabled: true
bundler-audit:
Expand All @@ -16,6 +16,7 @@ engines:
enabled: true
rubocop:
enabled: true
channel: rubocop-1-56-3
ratings:
paths:
- Gemfile.lock
Expand Down
24 changes: 3 additions & 21 deletions .devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,41 +36,23 @@
// Only bring up the services required by the development container - VSCode
// will bring up all services unless this is configured:
"runServices": [
"postgres"
"devcontainer" // had to add this when removing the postgres service...
],

"workspaceFolder": "/workspaces/sepomex",

// An array of extension IDs that specify the extensions to install inside the
// container when you first attach to it.
"extensions": [
// Integrates ESLint into VS Code:
"dbaeumer.vscode-eslint",

// Provides enhanced Ruby language and debugging support for Visual Studio
// Code:
"rebornix.ruby",

// execute rubocop for current Ruby code.
"misogi.ruby-rubocop",

// A language server that provides intellisense, code completion, and inline
// documentation for Ruby:
"castwide.solargraph",

// Search modules, class and methods in ruby files using vscode go to symbol:
"miguel-savignano.ruby-symbols",

// Git Lens:
"eamodio.gitlens",

// Github Pull Requests and Issues:
"github.vscode-pull-request-github",

// Remotely browse and edit any GitHub repository:
"github.remotehub",

// GitHub Copilot:
"github.copilot"
"github.copilot",
"qwtel.sqlite-viewer"
]
}
5 changes: 4 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ dev-entrypoint.sh

log/*.log

tmp/
tmp/*
!tmp/pids/
!tmp/pids
!tmp/pids/.keep

.rspec
spec/
Expand Down
29 changes: 0 additions & 29 deletions .github/workflows/ci-and-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,3 @@ jobs:
name: Integration
uses: ./.github/workflows/test-and-build.yml
secrets: inherit

deploy-to-staging:
name: Staging
uses: ./.github/workflows/deploy-to-cloud-run.yml
needs:
- test-and-build
with:
environment: staging
deploy-name: staging
cloud-sql-instance: sepomex-365521:us-central1:sepomex
cloud-sql-username-secret: database-username:latest
cloud-sql-password-secret: database-password:latest
cloud-run-service-suffix: ${{ needs.test-and-build.outputs.git-commit-short-sha }}
cloud-run-container-image: us-central1-docker.pkg.dev/sepomex-365521/icalialabs-sepomex/sepomex@${{ needs.test-and-build.outputs.container-image-digest }}

deploy-to-production:
name: Production
uses: ./.github/workflows/deploy-to-cloud-run.yml
needs:
- test-and-build
with:
environment: production
deploy-name: production
cloud-sql-instance: sepomex-365521:us-central1:sepomex
cloud-sql-username-secret: database-username:latest
cloud-sql-password-secret: database-password:latest
cloud-run-service-suffix: ${{ needs.test-and-build.outputs.git-commit-short-sha }}
cloud-run-container-image: us-central1-docker.pkg.dev/sepomex-365521/icalialabs-sepomex/sepomex@${{ needs.test-and-build.outputs.container-image-digest }}
# cloud-run-minimum-instances: 1 # Uncomment once we want it to be always on
35 changes: 14 additions & 21 deletions .github/workflows/test-and-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@ on:
description: "The Docker image digest which uniquely identifies the built image"
value: ${{ jobs.test-and-build.outputs.container-image-digest }}

# On this project, I went with a single "Test & Build" job, since each job
# gets billed rounded to the next minute, and having multiple separated jobs
# is not worth it at the beginning of the project.

# Keep in mind that, if the test suite becomes too big, and test threading is
# required, or the workflow speed becomes critial, we might need to revert back
# to separated jobs.
# On this project, was some changes to the original workflow, since we are hosting this
# project on Azure Web Apps, we don't need to deploy to Google Cloud Run, so we removed
# the deploy-to-staging and deploy-to-production jobs.
# Instead to deploy, we're just building the image and running the tests. The image will be
# pushed to the Dockerhub, because it's free and we don't need to pay for it.

jobs:
test-and-build:
Expand Down Expand Up @@ -83,21 +81,15 @@ jobs:
path: |
tmp/capybara/screenshots
- name: Authenticate to Google Cloud
uses: google-github-actions/auth@v0.8.0
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
service_account: github-actions@sepomex-365521.iam.gserviceaccount.com
workload_identity_provider: projects/582875546495/locations/global/workloadIdentityPools/github-pool/providers/github-provider

- name: Set up Google Cloud SDK
uses: google-github-actions/setup-gcloud@v0.6.0

- name: Authorize push to Google Cloud Artifact Registry
run: gcloud auth configure-docker us-central1-docker.pkg.dev
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build & Push Release Image
id: build-and-push-release-image
uses: docker/build-push-action@v3.1.1
uses: docker/build-push-action@v5
with:
push: true
target: release
Expand All @@ -106,9 +98,10 @@ jobs:
build-args: |
DEVELOPER_UID=${{ steps.variables.outputs.runner-uid }}
DEVELOPER_USERNAME=${{ steps.variables.outputs.runner-user }}
DEPLOY_NAME=production
tags: |
us-central1-docker.pkg.dev/sepomex-365521/icalialabs-sepomex/sepomex:${{ steps.variables.outputs.git-commit-short-sha }}
us-central1-docker.pkg.dev/sepomex-365521/icalialabs-sepomex/sepomex:${{ steps.variables.outputs.git-dasherized-branch }}
us-central1-docker.pkg.dev/sepomex-365521/icalialabs-sepomex/sepomex:latest
icalia/sepomex:${{ steps.variables.outputs.git-commit-short-sha }}
icalia/sepomex:${{ steps.variables.outputs.git-dasherized-branch }}
icalia/sepomex:latest
cache-from: type=gha
cache-to: type=gha,mode=max
37 changes: 37 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,46 @@
# See https://help.github.com/articles/ignoring-files for more about ignoring
# files.
#
# If you find yourself ignoring temporary files generated by your text editor
# or operating system, you probably want to add a global ignore instead:
# git config --global core.excludesfile '~/.gitignore_global'

# Ignore bundler config.
/.bundle

# Ignore the default SQLite database.
/db/*.sqlite3
/db/*.sqlite3-journal
/db/*.sqlite3-*

# Ignore all logfiles and tempfiles.
/log/*
/tmp/*
!/log/.keep
!/tmp/.keep

# Ignore pidfiles, but keep the directory.
/tmp/pids/*
!/tmp/pids
!/tmp/pids/.keep

# Ignore uploaded files in development.
/storage/*
!/storage/.keep

/public/assets
.byebug_history

# Ignore master key for decrypting credentials and more.
/config/master.key

.DS_Store

/db/development.sqlite3
/log/development.log
log/test.log


docker-compose.override.yml

# Ignore history files
Expand Down
25 changes: 25 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# The behavior of RuboCop can be controlled via the .rubocop.yml
# configuration file. It makes it possible to enable/disable
# certain cops (checks) and to alter their behavior if they accept
# any parameters. The file can be placed either in your home
# directory or in some project directory.
#
# RuboCop will start looking for the configuration file in the directory
# where the inspected file is and continue its way up to the root directory.
#
# See https://docs.rubocop.org/rubocop/configuration
# This is the configuration used by RuboCop. The item 'Enabled' will be read from the default configuration file, but can be overridden in this configuration file. See the RuboCop documentation for more information.

AllCops:
# Include common Ruby source files
Include:
- '**/*.gemspec'
- '**/Gemfile'
- '**/Rakefile'
# Exclude files that are not part of the project
Exclude:
- 'vendor/**/*'
- 'config/**/*'
- 'db/**/*'
- 'log/**/*'
- 'bin/**/*'
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ruby-2.7.5
ruby-3.0.7
18 changes: 13 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Stage 1: Runtime =============================================================
# The minimal package dependencies required to run the app in the release image:

# Use the official Ruby 2.7.5 Slim Bullseye image as base:
FROM ruby:2.7.5-slim-bullseye AS runtime
# Use the official Ruby 3.0 Slim Bullseye image as base:
FROM ruby:3.0.7-slim-bullseye AS runtime

# We'll set MALLOC_ARENA_MAX for optimization purposes & prevent memory bloat
# https://www.speedshop.co/2017/12/04/malloc-doubles-ruby-memory.html
Expand All @@ -13,7 +13,7 @@ RUN apt-get update \
&& apt-get install -y --no-install-recommends \
ca-certificates \
curl \
libpq5 \
libsqlite3-0 \
openssl \
# Required by mimemagic gem:
shared-mime-info \
Expand All @@ -33,7 +33,7 @@ RUN apt-get update \
&& apt-get install -y --no-install-recommends \
build-essential \
git \
libpq-dev
libsqlite3-dev

# Receive the developer user's UID and USER:
ARG DEVELOPER_UID=1000
Expand Down Expand Up @@ -215,6 +215,8 @@ RUN rm -rf \
# Use the "runtime" stage as base:
FROM runtime AS release

ARG DEPLOY_NAME=development

# Copy the remaining installed gems from the "builder" stage:
COPY --from=builder /usr/local/bundle /usr/local/bundle

Expand All @@ -228,17 +230,23 @@ USER nobody
# Set the RAILS and PORT default values:
ENV HOME=/workspaces/sepomex \
RAILS_ENV=production \
DEPLOY_NAME=${DEPLOY_NAME} \
RAILS_FORCE_SSL=yes \
RAILS_LOG_TO_STDOUT=yes \
RAILS_SERVE_STATIC_FILES=yes \
PORT=3000
PORT=80

# Test if the rails app loads:
RUN SECRET_KEY_BASE=10167c7f7654ed02b3557b05b88ece rails secret > /dev/null

# Set the installed app directory as the working directory:
WORKDIR /workspaces/sepomex

# Generate the sqlite production database:
RUN rails db:create \
&& rails db:migrate \
&& rake data:load

# Set the entrypoint script:
ENTRYPOINT [ "/workspaces/sepomex/bin/entrypoint" ]

Expand Down
8 changes: 4 additions & 4 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby '2.7.5'
ruby '3.0.7'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 6.0', '>= 6.0.3.2'

# Use pg as the database for Active Record
gem 'pg', '~> 1.1'
# Use sqlite3 as the database for Active Record
gem 'sqlite3', '~> 1.4'

# Use Puma as the app server
gem 'puma', '~> 4.3'
Expand Down Expand Up @@ -59,7 +59,7 @@ group :development do
gem 'rubocop-rspec', '~> 2.8', require: false

# IDE tools for code completion, inline documentation, and static analysis
gem 'solargraph', '~> 0.44.3', require: false
gem 'solargraph', '~> 0.50.0', require: false
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
Expand Down
Loading

0 comments on commit a9fa5af

Please sign in to comment.