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

family life gift card app #5

Open
wants to merge 69 commits into
base: initial
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 53 commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
7d1d6b3
rails 7 initial commit
andrewroth Nov 26, 2024
cd8ba9e
update build.sh and .ruby-version to what rails_8 was
andrewroth Nov 26, 2024
52cd8e8
WIP building out admin view to create gift cards
andrewroth Dec 2, 2024
4c904ca
WIP generating gift cards
andrewroth Dec 2, 2024
497781f
properly check existing ids with regex
andrewroth Dec 2, 2024
4349b2b
more tweaks and import script
andrewroth Dec 3, 2024
92212e1
fix numbering bug
andrewroth Dec 4, 2024
7e5610f
add back workflow for build-deploy-ecs
andrewroth Dec 4, 2024
7309aca
add +x to build.sh
andrewroth Dec 4, 2024
097c789
add libpq-dev for pg gem to build
andrewroth Dec 4, 2024
ee17a95
switch to copy of mobile-content-api Dockerfile
andrewroth Dec 4, 2024
1f87346
use maintenance Dockerfile and build.sh
andrewroth Dec 4, 2024
f1a0a6d
add monitor
andrewroth Dec 4, 2024
caece4a
rm test, we'll be using spec
andrewroth Dec 4, 2024
6cb75f2
add hosts and config for stage
andrewroth Dec 4, 2024
36f1100
it's staging and not stage
andrewroth Dec 4, 2024
8ca9f1e
add stage to production hosts to see if that makes it load
andrewroth Dec 9, 2024
da8c517
forgot to add staging
andrewroth Dec 9, 2024
d3558a5
add sidekiq and add api key model
andrewroth Dec 9, 2024
9d43a53
add secrets
andrewroth Dec 9, 2024
e34164b
fix ApiKey class not defining ApiKey properly
andrewroth Dec 9, 2024
0e3d608
add session store for staging
andrewroth Dec 10, 2024
50c6789
add .env for build that looks for some env vars
andrewroth Dec 10, 2024
292bf47
seems the redis initializer isn't necessary
andrewroth Dec 10, 2024
4c53375
copy args needed to build from one-app
andrewroth Dec 10, 2024
1793f32
disable sidekiq pro for now
andrewroth Dec 10, 2024
f9619f6
allow 10.* ips
andrewroth Dec 10, 2024
cc6d094
just disable sidekiq config for now
andrewroth Dec 10, 2024
457cd21
make sure sidekiq can start
andrewroth Dec 10, 2024
3651f43
support sidekiq pro
andrewroth Dec 10, 2024
3ca8f4c
pass in sidekiq pro creds
andrewroth Dec 10, 2024
491b594
use puma config from cap
andrewroth Dec 10, 2024
8cbd5b5
try to allow monitors/lb without host_authorization
andrewroth Dec 10, 2024
9fb0463
copy cutmeoff which allows monitor check without ssl
andrewroth Dec 10, 2024
5dd752c
use SITE_URL env var for allowed host to work in prod & stage
andrewroth Dec 10, 2024
1758cc6
add site_url to build
andrewroth Dec 10, 2024
a82312e
Merge branch 'staging' of github.com:CruGlobal/familylife-gift-cards …
andrewroth Dec 10, 2024
508a24c
use official redis db index
andrewroth Dec 11, 2024
7fa41f7
Update .github/workflows/build-deploy-ecs.yml
andrewroth Dec 11, 2024
0e07cf7
Merge branch 'rails_7_rebase' of github.com:CruGlobal/familylife-gift…
andrewroth Dec 11, 2024
3217cd5
Merge branch 'staging' into rails_7_rebase
andrewroth Dec 11, 2024
6edaf6c
Update Dockerfile
andrewroth Dec 11, 2024
476f170
various tweaks as per code review
andrewroth Dec 11, 2024
7009d7f
keep session for 30 days
andrewroth Dec 11, 2024
1208733
Merge branch 'rails_7_rebase' of github.com:CruGlobal/familylife-gift…
andrewroth Dec 11, 2024
54974ec
make sessions also last 30 days
andrewroth Dec 11, 2024
90955d1
Update app/models/issuance.rb
andrewroth Dec 11, 2024
f83024c
use issuing as state name instead of issued; various other code revie…
andrewroth Dec 12, 2024
5f0cc20
Merge branch 'rails_7_rebase' of github.com:CruGlobal/familylife-gift…
andrewroth Dec 12, 2024
c00f527
import final batch explicitly
andrewroth Dec 12, 2024
41dbb42
fix gift card type regex
andrewroth Dec 12, 2024
236c718
fix build error by copying ruby-version
andrewroth Dec 12, 2024
92d2075
Merge branch 'rails_7_rebase' of github.com:CruGlobal/familylife-gift…
andrewroth Dec 12, 2024
d3c4e69
add datadog
andrewroth Dec 12, 2024
cabe776
more state name change renames
andrewroth Dec 12, 2024
85a7275
use SITE_HOST for hosts allowed
andrewroth Dec 12, 2024
e970c9b
add SITE_HOST to build
andrewroth Dec 12, 2024
25acefd
fix crashes; add counts to initial import
andrewroth Dec 12, 2024
7007fad
start api; store copy of some gift card type fields in gift card
andrewroth Dec 13, 2024
0567fc9
set more values on issuance create gift cards
andrewroth Dec 13, 2024
a0ac1c6
Merge branch 'rails_7_rebase' of github.com:CruGlobal/familylife-gift…
andrewroth Dec 13, 2024
f01aed7
turns out some new columns were redundant
andrewroth Dec 13, 2024
fd9cd06
certificate value should be converted to decimal
andrewroth Dec 13, 2024
31589b3
hide skip_before_actions that don't exist for now
andrewroth Dec 13, 2024
e67817c
improve gift card admin table
andrewroth Dec 13, 2024
bb2ab55
remove prod and gl_account since they're redundant after all
andrewroth Dec 13, 2024
ef580b6
Merge branch 'rails_7_rebase' into staging
andrewroth Dec 13, 2024
9c55aa9
fix some issues with issuing new cards
andrewroth Dec 13, 2024
2726c67
get basic api working
andrewroth Dec 13, 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
9 changes: 9 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
RAILS_SERVE_STATIC_FILES=true
SITE_URL=https://familylife-gift-cards-stage.cru.org
SESSION_REDIS_DB_INDEX=59
SESSION_REDIS_HOST=localhost
SESSION_REDIS_PORT=6379
STORAGE_REDIS_DB_INDEX=59
STORAGE_REDIS_HOST=localhost
STORAGE_REDIS_PORT=6379
SECRET_KEY_BASE=secret
37 changes: 37 additions & 0 deletions .github/workflows/build-deploy-ecs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Build & Deploy ECS

on:
push:
branches:
# Automatically build and deploy main and staging. Additional branches may be added.
# - main
- staging
workflow_dispatch:
# Allows manual build and deploy of any branch/ref
inputs:
auto-deploy:
type: boolean
description: Deploy image after building?
required: true
default: 'false'

jobs:
# Build and push container image to ECR. Builds occur in the project repository.
build:
name: Build
uses: CruGlobal/.github/.github/workflows/build-ecs.yml@v1

# Triggers an ECS deployment in https://github.com/CruGlobal/cru-deploy/actions.
# All deployments happen in the cru-deploy repo.
deploy:
name: Deploy
runs-on: ubuntu-latest
needs: build
if: github.event_name != 'workflow_dispatch' || github.event.inputs.auto-deploy == 'true'
steps:
- uses: CruGlobal/.github/actions/trigger-deploy@v1
with:
github-token: ${{ secrets.CRU_DEPLOY_GITHUB_TOKEN }}
project-name: ${{ needs.build.outputs.project-name }}
environment: ${{ needs.build.outputs.environment }}
build-number: ${{ needs.build.outputs.build-number }}
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,7 @@ bin/deploy/erd-service-account.json
!/app/assets/builds/.keep

/node_modules

.byebug_history
*.zip
*.csv
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ruby-3.3.6
3.3.6
108 changes: 49 additions & 59 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,69 +1,59 @@
# syntax = docker/dockerfile:1
# RUBY_VERSION set by build.sh based on .ruby-version file
ARG RUBY_VERSION
FROM public.ecr.aws/docker/library/ruby:${RUBY_VERSION}-alpine

# This Dockerfile is designed for production, not development. Use with Kamal or build'n'run by hand:
# docker build -t my-app .
# docker run -d -p 80:80 -p 443:443 --name my-app -e RAILS_MASTER_KEY=<value from config/master.key> my-app
# DataDog logs source
LABEL com.datadoghq.ad.logs='[{"source": "ruby"}]'

# Make sure RUBY_VERSION matches the Ruby version in .ruby-version
ARG RUBY_VERSION=3.3.6
FROM docker.io/library/ruby:$RUBY_VERSION-slim AS base
# Create web application user to run as non-root
RUN addgroup -g 1000 webapp \
&& adduser -u 1000 -G webapp -s /bin/sh -D webapp \
&& mkdir -p /home/webapp/app
WORKDIR /home/webapp/app

# Rails app lives here
WORKDIR /rails
# Upgrade alpine packages (useful for security fixes)
RUN apk upgrade --no-cache

# Install base packages
RUN apt-get update -qq && \
apt-get install --no-install-recommends -y curl libjemalloc2 libvips sqlite3 && \
rm -rf /var/lib/apt/lists /var/cache/apt/archives
# Install rails/app dependencies
RUN apk --no-cache add libc6-compat git postgresql-libs tzdata

# Set production environment
ENV RAILS_ENV="production" \
BUNDLE_DEPLOYMENT="1" \
BUNDLE_PATH="/usr/local/bundle" \
BUNDLE_WITHOUT="development"
# Copy dependency definitions and lock files
COPY Gemfile Gemfile.lock .ruby-version ./

# Throw-away build stage to reduce size of final image
FROM base AS build
# Install bundler version which created the lock file and configure it
ARG SIDEKIQ_CREDS
RUN gem install bundler -v $(awk '/^BUNDLED WITH/ { getline; print $1; exit }' Gemfile.lock) \
&& bundle config --global gems.contribsys.com $SIDEKIQ_CREDS

# Install packages needed to build gems
RUN apt-get update -qq && \
apt-get install --no-install-recommends -y build-essential git pkg-config && \
rm -rf /var/lib/apt/lists /var/cache/apt/archives
# Install build-dependencies, then install gems, subsequently removing build-dependencies
RUN apk --no-cache add --virtual build-deps build-base postgresql-dev \
&& bundle install --jobs 20 --retry 2 \
&& apk del build-deps

# Install application gems
COPY Gemfile Gemfile.lock ./
RUN bundle install && \
rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git && \
bundle exec bootsnap precompile --gemfile

# Copy application code
# Copy the application
COPY . .

# Precompile bootsnap code for faster boot times
RUN bundle exec bootsnap precompile app/ lib/

# Precompiling assets for production without requiring secret RAILS_MASTER_KEY
RUN SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile




# Final stage for app image
FROM base

# Copy built artifacts: gems, application
COPY --from=build "${BUNDLE_PATH}" "${BUNDLE_PATH}"
COPY --from=build /rails /rails

# Run and own only the runtime files as a non-root user for security
RUN groupadd --system --gid 1000 rails && \
useradd rails --uid 1000 --gid 1000 --create-home --shell /bin/bash && \
chown -R rails:rails db log storage tmp
USER 1000:1000

# Entrypoint prepares the database.
ENTRYPOINT ["/rails/bin/docker-entrypoint"]

# Start the server by default, this can be overwritten at runtime
EXPOSE 3000
CMD ["./bin/rails", "server"]
# Environment required to build the application
ARG RAILS_ENV=production
ARG SESSION_REDIS_DB_INDEX=1
ARG SESSION_REDIS_HOST=localhost
ARG SESSION_REDIS_PORT=6379
ARG STORAGE_REDIS_DB_INDEX=1
ARG STORAGE_REDIS_HOST=localhost
ARG STORAGE_REDIS_PORT=6379
ARG SECRET_KEY_BASE=asdf
ARG SITE_URL=asdf

# Compile assets
RUN RAILS_ENV=$RAILS_ENV bundle exec rails assets:clobber assets:precompile \
&& chown -R webapp:webapp /home/webapp/

# Define volumes used by ECS to share public html and extra nginx config with nginx container
VOLUME /home/webapp/app/public
VOLUME /home/webapp/app/nginx-conf

# Run container process as non-root user
USER webapp

# Command to start rails
CMD ["bundle", "exec", "puma", "-C", "config/puma.rb"]
24 changes: 22 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
source "https://rubygems.org"

ruby file: ".ruby-version"

# Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main"
gem "rails", "~> 7.2.2"
# The original asset pipeline for Rails [https://github.com/rails/sprockets-rails]
gem "sprockets-rails"
gem "sassc-rails"

gem "pg"
gem "dotenv"

gem "sidekiq", "~> 6.5"
knutsenm marked this conversation as resolved.
Show resolved Hide resolved
source "https://gems.contribsys.com/" do
gem "sidekiq-pro"
end
gem "sidekiq-cron"
gem "sidekiq-failures"
gem "sidekiq-unique-jobs"

# Use the Puma web server [https://github.com/puma/puma]
gem "puma", ">= 5.0"
Expand All @@ -18,7 +27,8 @@ gem "stimulus-rails"
# Build JSON APIs with ease [https://github.com/rails/jbuilder]
gem "jbuilder"
# Use Redis adapter to run Action Cable in production
# gem "redis", ">= 4.0.1"
gem "redis", "~> 4.0"
gem "redis-actionpack"

# Use Kredis to get higher-level data types in Redis [https://github.com/rails/kredis]
# gem "kredis"
Expand Down Expand Up @@ -66,3 +76,13 @@ group :test do
end

gem "activeadmin", "~> 3.2"
gem "activeadmin_addons"

gem "aasm"

gem "activerecord-import"

gem "dogstatsd-ruby", "~> 5.3"

gem "ougai", "~> 1.7"
gem "amazing_print"
Loading
Loading