diff --git a/.ruby-gemset b/.ruby-gemset deleted file mode 100644 index 2ec5d75..0000000 --- a/.ruby-gemset +++ /dev/null @@ -1 +0,0 @@ -is_ruby_dead diff --git a/.ruby-version b/.ruby-version index ef538c2..be94e6f 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -3.1.2 +3.2.2 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..d1ab34e --- /dev/null +++ b/Dockerfile @@ -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"] diff --git a/Gemfile b/Gemfile index e48d060..142f50d 100644 --- a/Gemfile +++ b/Gemfile @@ -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' diff --git a/Gemfile.lock b/Gemfile.lock index 9fa85b6..8faf799 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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 diff --git a/app.rb b/app.rb index e6e7348..ef19b28 100644 --- a/app.rb +++ b/app.rb @@ -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 diff --git a/config.ru b/config.ru new file mode 100644 index 0000000..68cf33f --- /dev/null +++ b/config.ru @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +require './app' + +run App diff --git a/k8/configmap.yaml b/k8/configmap.yaml new file mode 100644 index 0000000..91b0081 --- /dev/null +++ b/k8/configmap.yaml @@ -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 diff --git a/k8/deployment.yaml b/k8/deployment.yaml new file mode 100644 index 0000000..1e96250 --- /dev/null +++ b/k8/deployment.yaml @@ -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 diff --git a/k8/ingress.yaml b/k8/ingress.yaml new file mode 100644 index 0000000..04df5eb --- /dev/null +++ b/k8/ingress.yaml @@ -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 diff --git a/k8/service.yaml b/k8/service.yaml new file mode 100644 index 0000000..781789d --- /dev/null +++ b/k8/service.yaml @@ -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 diff --git a/views/index.erb b/views/index.erb index 1fc67cd..414aad6 100644 --- a/views/index.erb +++ b/views/index.erb @@ -9,13 +9,6 @@ /ruby.png' /> - - ' /> - - - /ruby.png' /> - ' /> - /ruby.png'>