gogo

0ff0d66 · gmorell · 2026-04-27 21:15

11 files +221 -0

Files changed

added .gitlab-ci.yml
+11 −0
@@ -0,0 +1,11 @@
1 +build-master:
2 + retry: 1
3 + stage: build
4 + image:
5 + name: gcr.io/kaniko-project/executor:v1.23.2-debug
6 + entrypoint: [""]
7 + only:
8 + - master
9 + script:
10 + - echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"}}}" > /kaniko/.docker/config.json
11 + - /kaniko/executor --force --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/Dockerfile --destination $CI_REGISTRY_IMAGE --registry-mirror us0.regi.kube.gmp.io
added Dockerfile
+86 −0
@@ -0,0 +1,86 @@
1 +# Find eligible builder and runner images on Docker Hub. We use Ubuntu/Debian
2 +# instead of Alpine to avoid DNS resolution issues in production.
3 +#
4 +# - https://hub.docker.com/r/hexpm/elixir/tags
5 +# - https://hub.docker.com/_/debian?tab=tags&page=1&name=bookworm
6 +#
7 +ARG ELIXIR_VERSION=1.17.3
8 +ARG OTP_VERSION=27.2
9 +ARG DEBIAN_VERSION=bookworm-20241223-slim
10 +
11 +ARG BUILDER_IMAGE="hexpm/elixir:${ELIXIR_VERSION}-erlang-${OTP_VERSION}-debian-${DEBIAN_VERSION}"
12 +ARG RUNNER_IMAGE="debian:${DEBIAN_VERSION}"
13 +
14 +FROM ${BUILDER_IMAGE} as builder
15 +
16 +# install build dependencies
17 +RUN apt-get update -y && apt-get install -y build-essential git \
18 + && apt-get clean && rm -f /var/lib/apt/lists/*_*
19 +
20 +# prepare build dir
21 +WORKDIR /app
22 +
23 +# install hex + rebar
24 +RUN mix local.hex --force && \
25 + mix local.rebar --force
26 +
27 +# set build ENV
28 +ENV MIX_ENV="prod"
29 +
30 +# install mix dependencies
31 +COPY mix.exs mix.lock ./
32 +RUN mix deps.get --only $MIX_ENV
33 +RUN mkdir config
34 +
35 +# copy compile-time config files before we compile dependencies
36 +# to ensure any relevant config change will trigger the dependencies
37 +# to be re-compiled.
38 +COPY config/config.exs config/${MIX_ENV}.exs config/
39 +RUN mix deps.compile
40 +
41 +COPY priv priv
42 +COPY lib lib
43 +COPY assets assets
44 +
45 +# Tailwind + esbuild are managed via mix; no npm step needed.
46 +RUN mix assets.deploy
47 +
48 +# Compile the release
49 +RUN mix compile
50 +
51 +# Changes to config/runtime.exs don't require recompiling the code
52 +COPY config/runtime.exs config/
53 +
54 +COPY rel rel
55 +RUN mix release
56 +
57 +# start a new build stage so that the final image will only contain
58 +# the compiled release and other runtime necessities
59 +FROM ${RUNNER_IMAGE}
60 +
61 +RUN apt-get update -y && \
62 + apt-get install -y libstdc++6 openssl libncurses6 locales ca-certificates tini \
63 + && apt-get clean && rm -f /var/lib/apt/lists/*_*
64 +
65 +# Set the locale
66 +RUN sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && locale-gen
67 +
68 +ENV LANG=en_US.UTF-8 \
69 + LANGUAGE=en_US:en \
70 + LC_ALL=en_US.UTF-8
71 +
72 +WORKDIR "/app"
73 +RUN chown nobody /app
74 +
75 +# set runner ENV
76 +ENV MIX_ENV="prod"
77 +
78 +# Only copy the final release from the build stage
79 +COPY --from=builder --chown=nobody:root /app/_build/${MIX_ENV}/rel/diogramos ./
80 +
81 +USER nobody
82 +
83 +# tini reaps zombies + forwards signals so PostgreSQL connections get
84 +# closed cleanly on SIGTERM.
85 +ENTRYPOINT ["/usr/bin/tini", "--"]
86 +CMD ["/app/bin/server"]
added app.yml
+106 −0
@@ -0,0 +1,106 @@
1 +apiVersion: v1
2 +kind: Namespace
3 +metadata:
4 + name: diogramos
5 +---
6 +apiVersion: apps/v1
7 +kind: Deployment
8 +metadata:
9 + name: diogramos
10 + namespace: diogramos
11 + labels:
12 + name: diogramos
13 + keel.sh/policy: force
14 + keel.sh/trigger: poll
15 +spec:
16 + replicas: 2
17 + selector:
18 + matchLabels:
19 + name: diogramos
20 + strategy:
21 + type: RollingUpdate
22 + rollingUpdate:
23 + maxSurge: 1
24 + maxUnavailable: 0
25 + template:
26 + metadata:
27 + labels:
28 + name: diogramos
29 + spec:
30 + containers:
31 + - image: r.g.gmp.io/diogramos/diogramos:latest
32 + imagePullPolicy: Always
33 + name: diogramos
34 + ports:
35 + - containerPort: 4000
36 + env:
37 + - name: PHX_HOST
38 + value: diogramos.gmp.io
39 + - name: PORT
40 + value: "4000"
41 + - name: PHX_SERVER
42 + value: "true"
43 + - name: SECRET_KEY_BASE
44 + valueFrom:
45 + secretKeyRef:
46 + name: elixir-args
47 + key: secret_key_base
48 + - name: DATABASE_URL
49 + valueFrom:
50 + secretKeyRef:
51 + name: elixir-args
52 + key: database_url
53 + - name: POOL_SIZE
54 + value: "10"
55 + readinessProbe:
56 + httpGet:
57 + path: /
58 + port: 4000
59 + initialDelaySeconds: 5
60 + periodSeconds: 10
61 + livenessProbe:
62 + httpGet:
63 + path: /
64 + port: 4000
65 + initialDelaySeconds: 30
66 + periodSeconds: 30
67 + imagePullSecrets:
68 + - name: gitlabgmp
69 +---
70 +apiVersion: v1
71 +kind: Service
72 +metadata:
73 + name: diogramos-svc
74 + namespace: diogramos
75 +spec:
76 + ports:
77 + - port: 80
78 + targetPort: 4000
79 + protocol: TCP
80 + selector:
81 + name: diogramos
82 +---
83 +apiVersion: networking.k8s.io/v1
84 +kind: Ingress
85 +metadata:
86 + name: diogramos-ingress
87 + namespace: diogramos
88 + annotations:
89 + cert-manager.io/cluster-issuer: letsencrypt-prod
90 + kubernetes.io/ingress.class: "traefik"
91 +spec:
92 + tls:
93 + - hosts:
94 + - diogramos.gmp.io
95 + secretName: diogramos-tls
96 + rules:
97 + - host: diogramos.gmp.io
98 + http:
99 + paths:
100 + - path: /
101 + pathType: Prefix
102 + backend:
103 + service:
104 + name: diogramos-svc
105 + port:
106 + number: 80
modified mix.exs
+5 −0
@@ -85,6 +85,11 @@ defmodule Diogramos.MixProject do
85 85 "assets.setup": ["tailwind.install --if-missing", "esbuild.install --if-missing"],
86 86 "assets.build": ["compile", "tailwind diogramos", "esbuild diogramos"],
87 87 "assets.deploy": [
88 + # Compile must run before esbuild so Phoenix LiveView 1.1 has a
89 + # chance to emit colocated hooks under
90 + # `_build/$MIX_ENV/lib/<app>/priv/static/phoenix-colocated/<app>`,
91 + # which `assets/js/app.js` imports as `phoenix-colocated/diogramos`.
92 + "compile",
88 93 "tailwind diogramos --minify",
89 94 "esbuild diogramos --minify",
90 95 "phx.digest"
added rel/overlays/bin/migrate
+5 −0
@@ -0,0 +1,5 @@
1 +#!/bin/sh
2 +set -eu
3 +
4 +cd -P -- "$(dirname -- "$0")"
5 +exec ./diogramos eval Diogramos.Release.migrate
added rel/overlays/bin/migrate.bat
+1 −0
@@ -0,0 +1 @@
1 +call "%~dp0\diogramos" eval Diogramos.Release.migrate
added rel/overlays/bin/server
+5 −0
@@ -0,0 +1,5 @@
1 +#!/bin/sh
2 +set -eu
3 +
4 +cd -P -- "$(dirname -- "$0")"
5 +PHX_SERVER=true exec ./diogramos start
added rel/overlays/bin/server.bat
+2 −0
@@ -0,0 +1,2 @@
1 +set PHX_SERVER=true
2 +call "%~dp0\diogramos" start

Parents: 675e98f