develop #3

Merged
kbe merged 227 commits from develop into main 2025-09-16 14:35:23 +00:00
15 changed files with 1434 additions and 27 deletions
Showing only changes of commit ed659c423e - Show all commits

View File

@@ -2,21 +2,21 @@
# check=error=true # check=error=true
# This Dockerfile is designed for production, not development. Use with Kamal or build'n'run by hand: # This Dockerfile is designed for production, not development. Use with Kamal or build'n'run by hand:
# docker build -t aperonight . # docker build -t myapp .
# docker run -d -p 80:80 -e RAILS_MASTER_KEY=<value from config/master.key> --name aperonight aperonight # docker run -d -p 80:80 -e RAILS_MASTER_KEY=<value from config/master.key> --name myapp myapp
# For a containerized dev environment, see Dev Containers: https://guides.rubyonrails.org/getting_started_with_devcontainer.html # For a containerized dev environment, see Dev Containers: https://guides.rubyonrails.org/getting_started_with_devcontainer.html
# Make sure RUBY_VERSION matches the Ruby version in .ruby-version # Make sure RUBY_VERSION matches the Ruby version in .ruby-version
ARG RUBY_VERSION=3.4.4 ARG RUBY_VERSION=3.4.1
FROM docker.io/library/ruby:$RUBY_VERSION-slim AS base FROM docker.io/library/ruby:$RUBY_VERSION AS base
# Rails app lives here # Rails app lives here
WORKDIR /rails WORKDIR /rails
# Install base packages # Install base packages
RUN apt-get update -qq && \ RUN apt-get update -qq && \
apt-get install --no-install-recommends -y curl default-mysql-client libjemalloc2 libvips && \ apt-get install --no-install-recommends -y curl libjemalloc2 libvips && \
rm -rf /var/lib/apt/lists /var/cache/apt/archives rm -rf /var/lib/apt/lists /var/cache/apt/archives
# Set production environment # Set production environment
@@ -30,17 +30,17 @@ FROM base AS build
# Install packages needed to build gems and node modules # Install packages needed to build gems and node modules
RUN apt-get update -qq && \ RUN apt-get update -qq && \
apt-get install --no-install-recommends -y build-essential default-libmysqlclient-dev git libyaml-dev node-gyp pkg-config python-is-python3 && \ apt-get install --no-install-recommends -y build-essential git libyaml-dev node-gyp pkg-config python-is-python3 libmariadb-dev && \
rm -rf /var/lib/apt/lists /var/cache/apt/archives rm -rf /var/lib/apt/lists /var/cache/apt/archives
# Install JavaScript dependencies # Install JavaScript dependencies
ARG NODE_VERSION=24.4.1 ARG NODE_VERSION=18.19.0
ARG YARN_VERSION=1.22.22 ARG YARN_VERSION=latest
ENV PATH=/usr/local/node/bin:$PATH ENV PATH=/usr/local/node/bin:$PATH
RUN curl -sL https://github.com/nodenv/node-build/archive/master.tar.gz | tar xz -C /tmp/ && \ RUN curl -sL https://github.com/nodenv/node-build/archive/master.tar.gz | tar xz -C /tmp/ && \
/tmp/node-build-master/bin/node-build "${NODE_VERSION}" /usr/local/node && \ /tmp/node-build-master/bin/node-build "${NODE_VERSION}" /usr/local/node && \
npm install -g yarn@$YARN_VERSION && \
rm -rf /tmp/node-build-master rm -rf /tmp/node-build-master
RUN corepack enable && yarn set version $YARN_VERSION
# Install application gems # Install application gems
COPY Gemfile Gemfile.lock ./ COPY Gemfile Gemfile.lock ./
@@ -68,19 +68,34 @@ RUN rm -rf node_modules
# Final stage for app image # Final stage for app image
FROM base FROM base
ENV NODE_PATH=/usr/local/node
ENV PATH=/usr/local/node/bin:$PATH
# Install packages needed to build gems and node modules (for ci/cd)
RUN apt-get update -qq && \
apt-get install --no-install-recommends -y build-essential git libyaml-dev node-gyp pkg-config python-is-python3 mariadb-client && \
rm -rf /var/lib/apt/lists /var/cache/apt/archives
# Install rails gem
RUN gem install rails
# Copy built artifacts: gems, application # Copy built artifacts: gems, application
COPY --from=build "${BUNDLE_PATH}" "${BUNDLE_PATH}" COPY --from=build "${BUNDLE_PATH}" "${BUNDLE_PATH}"
COPY --from=build /rails /rails COPY --from=build /rails /rails
COPY --from=build "${NODE_PATH}" "${NODE_PATH}"
# Create a writeable node modules directory
# RUN mkdir node_modules
# Run and own only the runtime files as a non-root user for security # Run and own only the runtime files as a non-root user for security
RUN groupadd --system --gid 1000 rails && \ #RUN groupadd --system --gid 1000 rails && \
useradd rails --uid 1000 --gid 1000 --create-home --shell /bin/bash && \ # useradd rails --uid 1000 --gid 1000 --create-home --shell /bin/bash && \
chown -R rails:rails db log storage tmp # chown -R rails:rails db log storage tmp node_modules
USER 1000:1000 #USER 1000:1000
# Entrypoint prepares the database. # Entrypoint prepares the database.
ENTRYPOINT ["/rails/bin/docker-entrypoint"] ENTRYPOINT ["/rails/bin/docker-entrypoint"]
# Start server via Thruster by default, this can be overwritten at runtime # Start server via Thruster by default, this can be overwritten at runtime
EXPOSE 80 EXPOSE 80
CMD ["./bin/thrust", "./bin/rails", "server"] CMD ["./bin/thrust", "./bin/rails", "server", "-b", "0.0.0.0"]

View File

@@ -63,3 +63,5 @@ group :test do
gem "capybara" gem "capybara"
gem "selenium-webdriver" gem "selenium-webdriver"
end end
gem "devise", "~> 4.9"

View File

@@ -76,6 +76,7 @@ GEM
public_suffix (>= 2.0.2, < 7.0) public_suffix (>= 2.0.2, < 7.0)
ast (2.4.3) ast (2.4.3)
base64 (0.3.0) base64 (0.3.0)
bcrypt (3.1.20)
bcrypt_pbkdf (1.1.1) bcrypt_pbkdf (1.1.1)
benchmark (0.4.1) benchmark (0.4.1)
bigdecimal (3.2.2) bigdecimal (3.2.2)
@@ -103,6 +104,12 @@ GEM
debug (1.11.0) debug (1.11.0)
irb (~> 1.10) irb (~> 1.10)
reline (>= 0.3.8) reline (>= 0.3.8)
devise (4.9.4)
bcrypt (~> 3.0)
orm_adapter (~> 0.1)
railties (>= 4.1.0)
responders
warden (~> 1.2.3)
dotenv (3.1.8) dotenv (3.1.8)
drb (2.2.3) drb (2.2.3)
ed25519 (1.4.0) ed25519 (1.4.0)
@@ -183,6 +190,7 @@ GEM
racc (~> 1.4) racc (~> 1.4)
nokogiri (1.18.9-x86_64-linux-musl) nokogiri (1.18.9-x86_64-linux-musl)
racc (~> 1.4) racc (~> 1.4)
orm_adapter (0.5.0)
ostruct (0.6.3) ostruct (0.6.3)
parallel (1.27.0) parallel (1.27.0)
parser (3.3.9.0) parser (3.3.9.0)
@@ -249,6 +257,9 @@ GEM
regexp_parser (2.11.2) regexp_parser (2.11.2)
reline (0.6.2) reline (0.6.2)
io-console (~> 0.5) io-console (~> 0.5)
responders (3.1.1)
actionpack (>= 5.2)
railties (>= 5.2)
rexml (3.4.1) rexml (3.4.1)
rubocop (1.79.2) rubocop (1.79.2)
json (~> 2.3) json (~> 2.3)
@@ -328,6 +339,8 @@ GEM
unicode-emoji (4.0.4) unicode-emoji (4.0.4)
uri (1.0.3) uri (1.0.3)
useragent (0.16.11) useragent (0.16.11)
warden (1.2.9)
rack (>= 2.0.9)
web-console (4.2.1) web-console (4.2.1)
actionview (>= 6.0.0) actionview (>= 6.0.0)
activemodel (>= 6.0.0) activemodel (>= 6.0.0)
@@ -358,6 +371,7 @@ DEPENDENCIES
capybara capybara
cssbundling-rails cssbundling-rails
debug debug
devise (~> 4.9)
jbuilder jbuilder
jsbundling-rails jsbundling-rails
kamal kamal

View File

@@ -0,0 +1,9 @@
class PagesController < ApplicationController
# Display homepage
def home
end
# Display legal page
def legals
end
end

View File

@@ -0,0 +1,2 @@
module PagesHelper
end

View File

@@ -0,0 +1,55 @@
// app/javascript/controllers/logout_controller.js
import { Controller } from "@hotwired/stimulus";
export default class extends Controller {
static values = {
url: String,
};
connect() {
// Optional: Add confirmation message
//console.log("Hello LogoutController, Stimulus!", this.element);
// this.element.dataset.confirm = "Êtes-vous sûr de vouloir vous déconnecter ?";
}
signOut(event) {
event.preventDefault();
console.log("LogoutController#signOut mounted");
// Ensure user wants to disconnect with a confirmation request
// if (this.hasUrlValue && !confirm(this.element.dataset.confirm)) { return; }
// Retrieve the csrf token from header
const csrfToken = document.querySelector("[name='csrf-token']").content;
// Define url to redirect user when action is valid
const url = this.hasUrlValue ? this.urlValue : this.element.href;
// Use fetch to send logout request
fetch(url, {
method: "DELETE",
headers: {
"X-CSRF-Token": csrfToken,
Accept: "application/json",
"Content-Type": "application/json",
},
credentials: "same-origin",
})
.then((response) => {
// console.log(this.element.dataset.loginUrlValue); // By default, we does not return anything.
// By default the response does not include any url.
// Redirect to default login page (loginUrlValue)
if (response.redirected) {
window.location.href = response.url;
} else if (this.element.dataset.loginUrlValue) {
window.location.href = this.element.dataset.loginUrlValue;
return;
}
window.location.href = "/";
})
.catch((error) => {
console.error("Error during sign out:", error);
});
}
}

View File

@@ -0,0 +1,2 @@
<h1>Pages#home</h1>
<p>Find me in app/views/pages/home.html.erb</p>

View File

@@ -0,0 +1,2 @@
<h1>Pages#legals</h1>
<p>Find me in app/views/pages/legals.html.erb</p>

View File

@@ -10,11 +10,11 @@
# https://dev.mysql.com/doc/refman/5.7/en/password-hashing.html # https://dev.mysql.com/doc/refman/5.7/en/password-hashing.html
# #
default: &default default: &default
adapter: mysql2 adapter: mysql2 # Moved out from trilogy
encoding: utf8mb4 encoding: utf8mb4
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
username: root username: <%= ENV.fetch("DB_USERNAME") { "root" } %>
password: password: <%= ENV.fetch("DB_PASSWORD") { "root" } %>
host: <%= ENV.fetch("DB_HOST") { "127.0.0.1" } %> host: <%= ENV.fetch("DB_HOST") { "127.0.0.1" } %>
development: development:

View File

@@ -10,5 +10,5 @@ Rails.application.routes.draw do
# get "service-worker" => "rails/pwa#service_worker", as: :pwa_service_worker # get "service-worker" => "rails/pwa#service_worker", as: :pwa_service_worker
# Defines the root path route ("/") # Defines the root path route ("/")
# root "posts#index" root "pages#home"
end end

64
docker-compose.yml Normal file
View File

@@ -0,0 +1,64 @@
volumes:
mariadb_data:
gem_home:
node_modules_home:
networks:
default:
services:
mariadb:
image: mariadb:11.7.2-noble
env_file: .env
restart: unless-stopped
volumes:
- mariadb_data:/var/lib/mysql
#- ./mysql:/var/lib/mysql"
ports:
- "${FORWARD_DB_PORT:-3306}:3306"
environment:
MYSQL_ROOT_PASSWORD: "${DB_ROOT_PASSWORD:-root}"
# MYSQL_ROOT_HOST: "%"
MYSQL_PORT: "${DB_PORT:-3306}"
MYSQL_DATABASE: "${DB_DATABASE:-aperonight}"
MYSQL_USER: "${DB_USERNAME:-aperonight}"
MYSQL_PASSWORD: "${DB_PASSWORD:-aperonight}"
#MYSQL_ALLOW_EMPTY_PASSWORD: 1
networks:
- default
#command: mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_general_ci
rails:
build:
context: .
dockerfile: Dockerfile
env_file: .env
restart: unless-stopped
volumes:
- ./:/rails
- gem_home:/usr/local/bundle
- node_modules_home:/rails/node_modules
#- ./log:/var/log
#- ./log/supervisor:/var/log/supervisor
ports:
#- 80:80
- 3000:3000
#- 5000:5000
depends_on:
- mariadb
networks:
- default
#tty: true
#command: /opt/src/bin/dev
mailhog:
image: corpusops/mailhog:v1.0.1
# environment:
# - "mh_auth_file=/opt/mailhog/passwd.conf"
volumes:
- ./data/mailhog:/opt/mailhog
ports:
- 1025:1025 # smtp port 25
- 8025:8025 # web mail access
networks:
- default

1055
docs/architecture.txt Normal file

File diff suppressed because it is too large Load Diff

142
docs/branch-naming.txt Normal file
View File

@@ -0,0 +1,142 @@
Cette conversation a été générée avec Duck.ai (https://duck.ai) à l'aide du modèle Mistral Small 3 d'Mistral AI. Les chats IA peuvent afficher des informations inexactes ou offensantes (voir https://duckduckgo.com/duckai/privacy-terms pour en savoir plus).
====================
Message 1 sur 2 de l'utilisateur - 16/08/2025, 08:06:58:
In a git Ruby on Rails web project, how to name branches?
Mistral Small 3:
Naming branches in a Git Ruby on Rails web project (or any Git project) is an important aspect of maintaining a clean and understandable repository. Here are some best practices for naming branches:
1. **Use Descriptive Names**: The branch name should clearly describe the purpose or the feature being worked on. This helps other developers understand the context of the branch at a glance.
2. **Use Hyphens or Underscores**: Use hyphens (`-`) or underscores (`_`) to separate words in the branch name. This makes the name more readable.
3. **Prefix with the Type of Change**: Prefix the branch name with a type indicator such as `feature`, `bugfix`, `hotfix`, `release`, `chore`, `refactor`, `docs`, etc. This helps in categorizing the branches.
4. **Keep It Short but Meaningful**: While being descriptive, try to keep the branch name short to avoid clutter.
5. **Avoid Special Characters**: Stick to alphanumeric characters and hyphens/underscores. Avoid using special characters like `@`, `#`, `$`, etc.
6. **Use Lowercase Letters**: Consistently use lowercase letters to avoid case sensitivity issues.
Here are some examples of well-named branches:
- `feature/user-authentication`
- `bugfix/login-issue`
- `hotfix/critical-bug`
- `release/v1.2.0`
- `chore/update-dependencies`
- `refactor/user-model`
- `docs/update-readme`
### Example Workflow
1. **Creating a New Feature Branch**:
```sh
git checkout -b feature/user-authentication
```
2. **Creating a Bugfix Branch**:
```sh
git checkout -b bugfix/login-issue
```
3. **Creating a Hotfix Branch**:
```sh
git checkout -b hotfix/critical-bug
```
4. **Creating a Release Branch**:
```sh
git checkout -b release/v1.2.0
```
5. **Creating a Chore Branch**:
```sh
git checkout -b chore/update-dependencies
```
6. **Creating a Refactor Branch**:
```sh
git checkout -b refactor/user-model
```
7. **Creating a Docs Branch**:
```sh
git checkout -b docs/update-readme
```
By following these guidelines, you can maintain a well-organized and understandable branch structure in your Git repository, making collaboration and code management much easier.
--------------------
Message 2 sur 2 de l'utilisateur - 16/08/2025, 08:08:31:
Is it a good practice to use main, develop and functionnal names for branches?
Mistral Small 3:
Using `main`, `develop`, and feature branches is a common and widely accepted practice in Git workflows, particularly in the context of the Git Flow or GitHub Flow methodologies. Here's a breakdown of these branches and why they are useful:
1. **`main` Branch**:
- **Purpose**: The `main` branch (or sometimes called `master`) is the stable branch that always contains the production-ready code. It represents the current state of the project that is deployed to production.
- **Usage**: This branch should only contain code that has been thoroughly tested and is ready for release. It is typically protected to prevent direct commits and requires pull requests for changes.
- **Example**: `git checkout main`
2. **`develop` Branch**:
- **Purpose**: The `develop` branch is used for integrating features and preparing for the next release. It serves as a staging area for features that are in progress but not yet ready for production.
- **Usage**: Developers merge their feature branches into `develop` for integration testing. This branch can be less stable than `main` but should still be in a reasonably good state.
- **Example**: `git checkout develop`
3. **Feature Branches**:
- **Purpose**: Feature branches are used to develop new features, bug fixes, or any other isolated work. Each feature branch is created from `develop` and merged back into `develop` once the work is complete.
- **Usage**: These branches allow for parallel development without interfering with the stability of `develop` or `main`. They are typically named descriptively, as discussed earlier (e.g., `feature/user-authentication`, `bugfix/login-issue`).
- **Example**: `git checkout -b feature/user-authentication`
### Example Workflow
1. **Create a Feature Branch**:
```sh
git checkout develop
git pull origin develop
git checkout -b feature/user-authentication
```
2. **Develop the Feature**:
- Make changes, commit them, and push the branch to the remote repository.
```sh
git add .
git commit -m "Add user authentication feature"
git push origin feature/user-authentication
```
3. **Merge the Feature Branch into `develop`**:
- Once the feature is complete and tested, create a pull request to merge it into `develop`.
```sh
git checkout develop
git pull origin develop
git merge feature/user-authentication
git push origin develop
```
4. **Prepare for Release**:
- When preparing for a new release, create a release branch from `develop`.
```sh
git checkout -b release/v1.2.0
```
5. **Merge Release Branch into `main`**:
- After testing the release branch, merge it into `main` and tag the release.
```sh
git checkout main
git merge release/v1.2.0
git tag -a v1.2.0 -m "Release version 1.2.0"
git push origin main --tags
```
### Benefits
- **Stability**: The `main` branch remains stable and always contains production-ready code.
- **Integration**: The `develop` branch allows for continuous integration of features, making it easier to test and integrate new work.
- **Isolation**: Feature branches isolate work, allowing multiple developers to work on different features simultaneously without conflicts.
Using `main`, `develop`, and feature branches is a good practice as it helps maintain a clean, organized, and manageable repository, facilitating better collaboration and code management.

32
env.example Normal file
View File

@@ -0,0 +1,32 @@
# Application data
RAILS_ENV=production
SECRET_KEY_BASE=a3f5c6e7b8d9e0f1a2b3c4d5e6f7g8h9i0j1k2l3m4n5o6p7q8r9s0t1u2v3w4x5y6z7
DEVISE_SECRET_KEY=your_devise_secret_key_here
# Database Configuration for production and development
DB_HOST=mariadb
DB_ROOT_PASSWORD=root
DB_DATABASE=aperonight
DB_USERNAME=aperonight
DB_PASSWORD=aperonight
# Test database
DB_TEST_ADAPTER=sqlite3
DB_TEST_DATABASE=aperonight_test
DB_TEST_USERNAME=root
DB_TEST_USERNAME=root
# Mailer Configuration (for Devise and tests)
MAILER_DEFAULT_URL_OPTIONS=http://localhost:3000
# Test environment will use MailHog by default on 127.0.0.1:1025
SMTP_ADDRESS=127.0.0.1
SMTP_PORT=1025
# Optional auth (usually not required for MailHog)
# SMTP_USER_NAME=
# SMTP_PASSWORD=
# SMTP_DOMAIN=localhost
SMTP_AUTHENTICATION=plain
SMTP_ENABLE_STARTTLS=false
# Application variables
STRIPE_API_KEY=1337

View File

@@ -0,0 +1,13 @@
require "test_helper"
class PagesControllerTest < ActionDispatch::IntegrationTest
test "should get home" do
get pages_home_url
assert_response :success
end
test "should get legals" do
get pages_legals_url
assert_response :success
end
end