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

Use internal SQLite3 database #67

Merged
merged 32 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
cb1fdc8
Removed postgres service
vovimayhem Aug 14, 2022
93b7858
Replace postgres config with sqlite3
vovimayhem Aug 14, 2022
3d757f2
Fixed failing migrations
vovimayhem Aug 14, 2022
27cc982
fix ILIKE issue in SQLite
Wikitelmex Sep 20, 2022
3686367
generate values
Wikitelmex Sep 20, 2022
b50d985
loading data with indexes, next is start searching
Wikitelmex Sep 21, 2022
fedb8d7
state search done, new method alpharize to convert accented character…
Wikitelmex Sep 21, 2022
55c1faf
finish fixing zip code searches
Wikitelmex Sep 21, 2022
26a5b68
go to lunch, commit to continue
Wikitelmex Sep 21, 2022
5b2b068
fix specs
Wikitelmex Sep 23, 2022
2f0afd3
delete comments and fix format
Wikitelmex Sep 23, 2022
b2c43b6
description about populate db
Wikitelmex Sep 23, 2022
1bb2045
items per page flexibility added
Wikitelmex Sep 23, 2022
cea2e45
Merge branch 'main' into feature/use-internal-database
dvlex Apr 23, 2024
2b358a7
add to devcontainer sqlite extension
dvlex Apr 23, 2024
7e136db
change the port to 80 to avoid aditional azure config
dvlex Apr 24, 2024
ce0efd3
keep the pids folder, because it causes a failure
dvlex Apr 24, 2024
315c994
fix gitignore issue
dvlex Apr 24, 2024
f764272
fix deletion of pids folder that causes a issue when build and deploy
dvlex Apr 24, 2024
1fb3c3d
add ci/cd to dockerhub/azure
dvlex Apr 25, 2024
293cc91
Update CI & CD workflow to trigger on workflow_dispatch event for tes…
dvlex Apr 25, 2024
26b6f4c
test pr flow
dvlex Apr 25, 2024
7905f5a
change to main
dvlex Apr 25, 2024
5d61aab
fix codeclimate issue try 1
dvlex Apr 26, 2024
9ea3384
try 2
dvlex Apr 26, 2024
c909a01
try 3
dvlex Apr 26, 2024
f463dc0
try 4
dvlex Apr 26, 2024
ca67fbb
try 5
dvlex Apr 26, 2024
8d3aa3b
try 6
dvlex Apr 26, 2024
3c7567e
try 6
dvlex Apr 26, 2024
dd8a89f
try 7
dvlex Apr 26, 2024
bf8621a
try 8
dvlex Apr 26, 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
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/[email protected]
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
service_account: [email protected]
workload_identity_provider: projects/582875546495/locations/global/workloadIdentityPools/github-pool/providers/github-provider

- name: Set up Google Cloud SDK
uses: google-github-actions/[email protected]

- 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