Skip to content

Commit

Permalink
Update ruby to 3.2.2
Browse files Browse the repository at this point in the history
- Add Dockerfile and k8 configs
  • Loading branch information
pbstriker38 committed Nov 25, 2023
1 parent 0c26ef6 commit c7dfb47
Show file tree
Hide file tree
Showing 12 changed files with 200 additions and 18 deletions.
1 change: 0 additions & 1 deletion .ruby-gemset

This file was deleted.

2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.1.2
3.2.2
64 changes: 64 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Global build args
ARG GIT_SHA=unspecified
ARG RACK_ENV=production

# Build image
FROM ruby:3.2.2-alpine as BUILD_IMAGE

# https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#using-pipes
SHELL ["/bin/ash", "-eo", "pipefail", "-c"]

# https://docs.docker.com/build/cache/#use-the-dedicated-run-cache
RUN --mount=type=cache,target=/var/cache/apk \
apk add --no-cache build-base

ENV APP_HOME /app

RUN mkdir $APP_HOME
WORKDIR $APP_HOME

COPY Gemfile* $APP_HOME/

# Run bundler in deployment mode
RUN bundle config set deployment 'true' && \
bundle config set without 'development test' && \
bundle config set path 'vendor/bundle'

# Install gems and remove unnecessary files
RUN MAKE="make --jobs $(($(nproc)+1))" bundle install --jobs "$(nproc)" --retry 3 \
&& rm -rf vendor/bundle/ruby/*/cache/*.gem \
&& find vendor/bundle/ruby/*/gems/ -type f -name "*.c" -delete \
&& find vendor/bundle/ruby/*/gems/ -type f -name "*.o" -delete \
&& find vendor/bundle/ruby/*/gems/ -type f -name "*.md" -delete \
&& find vendor/bundle/ruby/*/gems/ -name "test" -type d -exec rm -rf {} + \
&& find vendor/bundle/ruby/*/gems/ -name "spec" -type d -exec rm -rf {} +

COPY . $APP_HOME

# Final image
FROM ruby:3.2.2-alpine

ARG GIT_SHA
ARG RACK_ENV

LABEL git-sha=${GIT_SHA}

RUN adduser -D --uid 1001 ruby
USER 1001

ENV APP_HOME /home/ruby
WORKDIR $APP_HOME

# Copy the app from the BUILD_IMAGE
COPY --from=BUILD_IMAGE --chown=ruby /app $APP_HOME

# Copy the bundle configuration from the BUILD_IMAGE
COPY --from=BUILD_IMAGE --chown=ruby $BUNDLE_APP_CONFIG/config $BUNDLE_APP_CONFIG/config

ENV RACK_ENV=${RACK_ENV} \
GIT_SHA=${GIT_SHA} \
REQUIRE_DOTENV=false

EXPOSE 9292

CMD ["bundle", "exec", "puma", "-e", "production"]
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
source 'https://rubygems.org'
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }

ruby '3.1.2'
ruby '3.2.2'

gem 'sinatra', '~> 2.2'
gem 'puma', '~> 5.6'
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ DEPENDENCIES
sinatra (~> 2.2)

RUBY VERSION
ruby 3.1.2p20
ruby 3.2.2p53

BUNDLED WITH
2.3.12
2.4.19
14 changes: 8 additions & 6 deletions app.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
require 'sinatra'
require_relative 'answer_randomizer'

get '/' do
@answer = AnswerRandomizer.random_answer
class App < Sinatra::Base
get '/' do
@answer = AnswerRandomizer.random_answer

erb :index
end
erb :index
end

get '/ruby.png' do
send_file 'ruby.png'
get '/ruby.png' do
send_file 'ruby.png'
end
end
5 changes: 5 additions & 0 deletions config.ru
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true

require './app'

run App
11 changes: 11 additions & 0 deletions k8/configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
apiVersion: v1
data:
APP_ENV: production
PORT: "9292"
RACK_ENV: production
APP_URL: "https://is-ruby-dead.pbstriker38.dev/"
kind: ConfigMap
metadata:
name: is-ruby-dead
namespace: default
69 changes: 69 additions & 0 deletions k8/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: is-ruby-dead
namespace: default
---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: is-ruby-dead
app.kubernetes.io/name: is-ruby-dead
version: v1.0.0
name: is-ruby-dead
namespace: default
spec:
progressDeadlineSeconds: 600
replicas: 1
revisionHistoryLimit: 10
selector:
matchLabels:
app: is-ruby-dead
strategy:
rollingUpdate:
maxSurge: 25%
maxUnavailable: 25%
type: RollingUpdate
template:
metadata:
labels:
app: is-ruby-dead
app.kubernetes.io/name: is-ruby-dead
version: v1.0.0
spec:
securityContext:
seccompProfile:
type: RuntimeDefault
containers:
- name: web
envFrom:
- configMapRef:
name: is-ruby-dead
- secretRef:
name: is-ruby-dead
image: pbstriker38/is-ruby-dead:v1.0.0
imagePullPolicy: IfNotPresent
securityContext:
allowPrivilegeEscalation: false
runAsNonRoot: true
capabilities:
drop: ["ALL"]
ports:
- containerPort: 9292
protocol: TCP
resources:
limits:
memory: 200Mi
requests:
cpu: 50m
memory: 100Mi
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
dnsPolicy: ClusterFirst
restartPolicy: Always
schedulerName: default-scheduler
serviceAccount: is-ruby-dead
serviceAccountName: is-ruby-dead
terminationGracePeriodSeconds: 30
24 changes: 24 additions & 0 deletions k8/ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: is-ruby-dead
namespace: default
annotations:
cert-manager.io/cluster-issuer: "letsencrypt-prod"
spec:
ingressClassName: nginx
rules:
- host: is-ruby-dead.pbstriker38.dev
http:
paths:
- pathType: Prefix
backend:
service:
name: is-ruby-dead
port:
number: 80
path: /
tls:
- hosts:
- is-ruby-dead.pbstriker38.dev
secretName: is-ruby-dead-tls
15 changes: 15 additions & 0 deletions k8/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
apiVersion: v1
kind: Service
metadata:
name: is-ruby-dead
namespace: default
spec:
ports:
- name: http
port: 80
protocol: TCP
targetPort: 9292
selector:
app: is-ruby-dead
type: ClusterIP
7 changes: 0 additions & 7 deletions views/index.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,6 @@
<meta property='og:description' content="A 'live', up to date look at Ruby's status as a language." />
<meta property='og:image' content='<%= ENV['APP_URL'] %>/ruby.png' />

<meta name='twitter:card' content='summary' />
<meta name='twitter:domain' value='<%= ENV['APP_DOMAIN'] %>' />
<meta name='twitter:title' value='Is Ruby Dead?' />
<meta name='twitter:description' value="A 'live', up to date look at Ruby's status as a language." />
<meta name='twitter:image' content='<%= ENV['APP_URL'] %>/ruby.png' />
<meta name='twitter:url' value='<%= ENV['APP_URL'] %>' />

<link rel='icon' type='image/png' href='<%= ENV['APP_URL'] %>/ruby.png'>

<title>Is Ruby Dead?</title>
Expand Down

0 comments on commit c7dfb47

Please sign in to comment.