1
0
mirror of https://github.com/jcwimer/wrestlingApp synced 2026-03-24 17:04:43 +00:00

Upgraded to rails 8.0.2, moved from dalli to solid cache, moved from delayed_job to solid queue, and add solid cable. deploy/rails-dev-run.sh no longer needs to chmod. Fixed finished_at callback for matches. Migrated from Devise to built in rails auth. Added view tests for the bracket page testing that all bout numbers render for all matches in each bracket type.

This commit is contained in:
2025-04-08 17:54:42 -04:00
parent 9c25a6cc39
commit 2d433b680a
118 changed files with 4921 additions and 1341 deletions

View File

@@ -1,11 +1,5 @@
#!/bin/bash
project_dir="$(dirname $( dirname $(readlink -f ${BASH_SOURCE[0]})))"
RAM_KB=$(grep MemTotal /proc/meminfo | awk '{print $2}')
RAM_MB=$(expr $RAM_KB / 1024)
RAM_GB=$(expr $RAM_MB / 1024)
RAM_WITHOUT_OTHER_SERVICES=$(expr $RAM_MB - 1024) # other services use ~1024MB of RAM
PASSENGER_POOL_FACTOR=$(expr $RAM_WITHOUT_OTHER_SERVICES / 256) # 1 pool worker uses ~256MB of RAM
export PASSENGER_POOL_SIZE=$(expr $PASSENGER_POOL_FACTOR '*' 1)
#docker build -t wrestlingdev:test -f ${project_dir}/deploy/rails-prod-Dockerfile ${project_dir}
docker-compose -f ${project_dir}/deploy/docker-compose-test.yml kill
@@ -13,6 +7,7 @@ docker-compose -f ${project_dir}/deploy/docker-compose-test.yml build
docker-compose -f ${project_dir}/deploy/docker-compose-test.yml up -d
sleep 30s
# echo Make sure your local mysql database has a wrestlingtourney db
# docker-compose -f ${project_dir}/deploy/docker-compose-test.yml exec -T app bash -c "DISABLE_DATABASE_ENVIRONMENT_CHECK=1 rake db:drop"
docker-compose -f ${project_dir}/deploy/docker-compose-test.yml exec -T app rake db:create
docker-compose -f ${project_dir}/deploy/docker-compose-test.yml exec -T app rake db:migrate

View File

@@ -21,14 +21,13 @@ services:
- WRESTLINGDEV_DB_PWD=password
- WRESTLINGDEV_DB_HOST=db
- WRESTLINGDEV_DB_PORT=3306
- MEMCACHIER_SERVERS=memcached:11211
- MEMCACHIER_PASSWORD=
- WRESTLINGDEV_DEVISE_SECRET_KEY=2f29d49db6704377ba263f7cb9db085b386bcb301c0cd501126a674686ab1a109754071165b08cd72af03cec4642a4dd04361c994462254dd5d85e9594e8b9aa
- WRESTLINGDEV_SECRET_KEY_BASE=077cdbef5c2ccf22543fb17a67339f234306b7fa2e1e4463d851c444c10a5611829a2290b253da78339427f131571fac9a42c83d960b2d25ecc10a4a0a7ce1a2
- WRESTLINGDEV_INFLUXDB_DATABASE=wrestlingdev
- WRESTLINGDEV_INFLUXDB_HOST=influxdb
- WRESTLINGDEV_INFLUXDB_PORT=8086
- PASSENGER_POOL_SIZE=${PASSENGER_POOL_SIZE}
- SOLID_QUEUE_IN_PUMA=true
networks:
database:
caching:
@@ -58,30 +57,6 @@ services:
timeout: 5s
retries: 10
worker:
image: wrestlingdev
environment:
- RAILS_ENV=production
- WRESTLINGDEV_DB_NAME=wrestlingtourney
- WRESTLINGDEV_DB_USR=root
- WRESTLINGDEV_DB_PWD=password
- WRESTLINGDEV_DB_HOST=db
- WRESTLINGDEV_DB_PORT=3306
- MEMCACHIER_SERVERS=memcached:11211
- MEMCACHIER_PASSWORD=
- WRESTLINGDEV_DEVISE_SECRET_KEY=2f29d49db6704377ba263f7cb9db085b386bcb301c0cd501126a674686ab1a109754071165b08cd72af03cec4642a4dd04361c994462254dd5d85e9594e8b9aa
- WRESTLINGDEV_SECRET_KEY_BASE=077cdbef5c2ccf22543fb17a67339f234306b7fa2e1e4463d851c444c10a5611829a2290b253da78339427f131571fac9a42c83d960b2d25ecc10a4a0a7ce1a2
- WRESTLINGDEV_INFLUXDB_DATABASE=wrestlingdev
- WRESTLINGDEV_INFLUXDB_HOST=influxdb
- WRESTLINGDEV_INFLUXDB_PORT=8086
- PASSENGER_POOL_SIZE=${PASSENGER_POOL_SIZE}
networks:
database:
caching:
metrics:
restart: always
command: bundle exec bin/delayed_job -n 1 run
influxdb:
image: influxdb:1.8-alpine
environment:
@@ -92,10 +67,3 @@ services:
metrics:
volumes:
- influxdb:/var/lib/influxdb
memcached:
image: memcached:1.5
mem_limit: "64000000"
restart: always
networks:
caching:

View File

@@ -11,7 +11,7 @@ spec:
image: jcwimer/wrestlingdev:prod
imagePullPolicy: Always
command: ["/bin/sh","-c"]
args: ["bundle exec rake db:create; bundle exec rake db:migrate"]
args: ["bundle exec rake db:create; bundle exec rake db:migrate;"]
env:
- name: RAILS_ENV
value: production

View File

@@ -13,16 +13,20 @@ spec:
clusterIP: None
---
apiVersion: apps/v1
kind: Deployment
# Use a statefulset instead of a deployment because we need to have a unique identity for each pod
# for solid queue to work properly and solid queue is running with puma threads
kind: StatefulSet
metadata:
name: wrestlingdev-app-deployment
name: wrestlingdev-app
labels:
app: wrestlingdev
spec:
replicas: 2
serviceName: wrestlingdev-app
selector:
matchLabels:
app: wrestlingdev
tier: frontend
template:
metadata:
labels:
@@ -34,12 +38,16 @@ spec:
image: jcwimer/wrestlingdev:prod
imagePullPolicy: Always
command: ["bundle"]
args: ["exec", "passenger", "start", "-p", "80", "--max-pool-size", "2","--environment", "production"]
args: ["exec", "rails", "server", "-e", "production", "-p", "80", "-b", "0.0.0.0"]
ports:
- containerPort: 80
env:
- name: RAILS_ENV
value: production
- name: SOLID_QUEUE_IN_PUMA
value: "true"
- name: REVERSE_PROXY_SSL_TERMINATION
value: "true"
- name: PASSENGER_POOL_SIZE
valueFrom:
secretKeyRef:
@@ -135,94 +143,4 @@ spec:
# resource:
# name: memory
# targetAverageValue: 100Mi
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: wrestlingdev-worker
labels:
app: wrestlingdev
spec:
replicas: 2
selector:
matchLabels:
app: wrestlingdev
serviceName: wrestlingdev-worker
template:
metadata:
labels:
app: wrestlingdev
tier: worker
spec:
containers:
- name: wrestlingdev-worker
image: jcwimer/wrestlingdev:prod
imagePullPolicy: Always
env:
- name: RAILS_ENV
value: production
- name: WRESTLINGDEV_DB_NAME
value: wrestlingdev
- name: WRESTLINGDEV_DB_USR
valueFrom:
secretKeyRef:
name: wrestlingdev-secrets
key: dbusername
- name: WRESTLINGDEV_DB_PWD
valueFrom:
secretKeyRef:
name: wrestlingdev-secrets
key: dbpassword
- name: WRESTLINGDEV_DB_PORT
value: "3306"
- name: MEMCACHIER_SERVERS
value: wrestlingdev-memcached:11211
- name: WRESTLINGDEV_DB_HOST
valueFrom:
secretKeyRef:
name: wrestlingdev-secrets
key: dbhost
- name: WRESTLINGDEV_DEVISE_SECRET_KEY
valueFrom:
secretKeyRef:
name: wrestlingdev-secrets
key: devisesecretkey
- name: WRESTLINGDEV_SECRET_KEY_BASE
valueFrom:
secretKeyRef:
name: wrestlingdev-secrets
key: railssecretkey
- name: WRESTLINGDEV_EMAIL_PWD
valueFrom:
secretKeyRef:
name: wrestlingdev-secrets
key: gmailpassword
- name: WRESTLINGDEV_EMAIL
valueFrom:
secretKeyRef:
name: wrestlingdev-secrets
key: gmailemail
- name: WRESTLINGDEV_INFLUXDB_DATABASE
valueFrom:
secretKeyRef:
name: wrestlingdev-secrets
key: influxdb_database
- name: WRESTLINGDEV_INFLUXDB_HOST
valueFrom:
secretKeyRef:
name: wrestlingdev-secrets
key: influxdb_hostname
- name: WRESTLINGDEV_INFLUXDB_PORT
valueFrom:
secretKeyRef:
name: wrestlingdev-secrets
key: influxdb_port
command: ["bundle"]
args: ["exec", "bin/delayed_job", "-n", "1", "run"]
# resources:
# limits:
# memory: "512Mi"
# requests:
# memory: "200Mi"
# cpu: "0.2"

View File

@@ -1,5 +1,9 @@
FROM ruby:3.2.0
# Accept build arguments for user/group IDs
ARG USER_ID=1000
ARG GROUP_ID=1000
RUN apt-get -qq update \
&& apt-get -qq install -y \
build-essential \
@@ -17,21 +21,62 @@ RUN echo "America/New_York" > /etc/timezone \
&& rm /etc/localtime \
&& ln -s /usr/share/zoneinfo/America/New_York /etc/localtime
RUN echo 'gem: --no-rdoc --no-ri' > /root/.gemrc
# Install gems as root first
RUN gem install bundler
RUN gem update --system
# Add Gemfile before creating user (still as root)
ADD Gemfile* /tmp/
WORKDIR /tmp
RUN bundle config set without 'production'
RUN bundle install --jobs 4
RUN mkdir /rails
# Create a non-root user with the provided user/group IDs
# Use existing group if GID already exists
RUN if grep -q ":${GROUP_ID}:" /etc/group; then \
GROUP_NAME=$(getent group ${GROUP_ID} | cut -d: -f1); \
else \
GROUP_NAME=devuser; \
groupadd -g $GROUP_ID $GROUP_NAME; \
fi && \
useradd -u $USER_ID -g $GROUP_ID -m -s /bin/bash devuser \
&& echo "devuser ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/devuser \
&& chmod 0440 /etc/sudoers.d/devuser
# Now that user exists, set up permissions
RUN echo 'gem: --no-rdoc --no-ri' > /home/devuser/.gemrc \
&& mkdir -p /home/devuser/.bundle \
&& chown -R ${USER_ID}:${GROUP_ID} /home/devuser /tmp/Gemfile* \
&& chmod -R 777 /usr/local/bundle
# Switch to the non-root user for all subsequent commands
USER devuser
# Pre-install gems from Gemfile
WORKDIR /tmp
RUN bundle config set --local without 'production' && \
bundle install --jobs 4
# Create the rails directory with correct ownership
RUN sudo mkdir -p /rails && sudo chown ${USER_ID}:${GROUP_ID} /rails
WORKDIR /rails
ADD . /rails
# Add helper script to initialize the project
RUN echo '#!/bin/bash\n\
if [ ! -f "bin/rails" ]; then\n\
echo "Setting up Rails binstubs..."\n\
bundle binstubs --all\n\
echo "Rails setup complete. You can now use bin/rails."\n\
else\n\
echo "Rails binstubs already exist."\n\
fi\n\
exec "$@"\n\
' > /home/devuser/init_rails.sh \
&& chmod +x /home/devuser/init_rails.sh
VOLUME ["/rails"]
EXPOSE 3000
ENV SOLID_QUEUE_IN_PUMA=true
CMD /bin/bash
# Use the init script as entrypoint
ENTRYPOINT ["/home/devuser/init_rails.sh"]
CMD ["/bin/bash"]

View File

@@ -52,10 +52,8 @@ EXPOSE 443
# Tini solves the zombie PID problem
ENTRYPOINT ["/tini", "--"]
CMD bundle exec passenger start --max-pool-size ${PASSENGER_POOL_SIZE} --min-instances ${PASSENGER_POOL_SIZE} --environment production -p 80
# Higher max pool uses more ram
# Followed recommendation from: https://blog.phusion.nl/2015/11/10/heroku-and-passenger-focus-on-the-app-performance/
# Enable Solid Queue to run inside Puma
ENV SOLID_QUEUE_IN_PUMA=true
#CMD bundle exec puma -w 3 -t 5:5 -b 'tcp://0.0.0.0:80' -e production
#CMD bundle exec puma -w 3 -t 5:5 -b 'ssl://0.0.0.0:443?key=/ssl/server.key&verify_mode=none&cert=/ssl/server.crt' -e production
#CMD bundle exec passenger start --max-pool-size 3 --environment production --ssl --ssl-certificate /ssl/server.crt --ssl-certificate-key /ssl/server.key
# Use rails server instead of Puma directly to ensure Rails environment is loaded
CMD bundle exec rails server -e production -p 80 -b '0.0.0.0'