Skip to content

Commit 0aada78

Browse files
committed
feat(deploy): Add deployment with Podman
1 parent 54ddba0 commit 0aada78

File tree

7 files changed

+127
-0
lines changed

7 files changed

+127
-0
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ repos:
44
rev: v6.0.0
55
hooks:
66
- id: check-yaml
7+
args: [ --allow-multiple-documents ]
78
- id: check-toml
89
- id: end-of-file-fixer
910
- id: trailing-whitespace

deploy/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
db_init/
2+
app-secrets.yaml

deploy/app-pod.kube

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[Unit]
2+
Description=App pod
3+
4+
[Install]
5+
WantedBy=multi-user.target default.target
6+
7+
[Kube]
8+
Yaml=/home/user/app/deploy/app-pod.yaml
9+
Network=app.network
10+
SetWorkingDirectory=yaml

deploy/app-pod.yaml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
name: app
5+
data:
6+
TZ: UTC
7+
ALLOWED_HOSTS: "*"
8+
---
9+
apiVersion: v1
10+
kind: Pod
11+
metadata:
12+
labels:
13+
app: app
14+
name: app-pod
15+
spec:
16+
containers:
17+
- name: db
18+
image: postgres:18
19+
envFrom:
20+
- configMapRef:
21+
name: app
22+
- secretRef:
23+
name: app
24+
securityContext:
25+
runAsUser: 920
26+
runAsGroup: 920
27+
ports:
28+
- containerPort: 5432
29+
volumeMounts:
30+
- mountPath: /docker-entrypoint-initdb.d/:z
31+
name: app-db-init
32+
readOnly: true
33+
- mountPath: /var/lib/postgresql/data:Z,U
34+
name: app-db-pvc
35+
- mountPath: /var/run/postgresql:Z
36+
name: app-db-tmp
37+
38+
- name: api
39+
image: app_api:latest
40+
envFrom:
41+
- configMapRef:
42+
name: app
43+
- secretRef:
44+
name: app
45+
securityContext:
46+
runAsUser: 921
47+
runAsGroup: 921
48+
ports:
49+
- containerPort: 8000
50+
hostPort: 10101
51+
52+
- name: web
53+
image: app_web:latest
54+
envFrom:
55+
- configMapRef:
56+
name: app
57+
securityContext:
58+
runAsUser: 922
59+
runAsGroup: 922
60+
ports:
61+
- containerPort: 3000
62+
hostPort: 10102
63+
64+
volumes:
65+
- name: app-db-init
66+
hostPath:
67+
path: ./db_init/
68+
type: DirectoryOrCreate
69+
- name: app-db-pvc
70+
persistentVolumeClaim:
71+
claimName: app-db-pvc
72+
- name: app-db-tmp
73+
emptyDir: { }

deploy/app-secrets.example.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
apiVersion: v1
2+
kind: Secret
3+
metadata:
4+
name: app
5+
stringData:
6+
POSTGRES_USER: pguser
7+
POSTGRES_PASSWORD: pgsecret
8+
POSTGRES_DB: app
9+
DATABASE_URL: postgresql+psycopg://pguser:pgsecret@postgres:5432/app
10+
SECRET_KEY: secretkey

deploy/app.network

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[Network]
2+
NetworkName=app

deploy/build.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env bash
2+
3+
tag_prefix="app"
4+
date=$(date '+%Y%m%d')
5+
6+
build_image() {
7+
local target=$1
8+
local dir=$2
9+
podman build --pull=newer -t "${tag_prefix}_${target}:${date}" -t "${tag_prefix}_${target}:latest" "${dir}/"
10+
}
11+
12+
build_target=${1:-all}
13+
14+
case $build_target in
15+
api)
16+
build_image "api" ../app_api/
17+
;;
18+
web)
19+
build_image "web" ../app_web/
20+
;;
21+
all)
22+
build_image "api" ../app_api/
23+
build_image "web" ../app_web/
24+
;;
25+
*)
26+
echo "Uso: $0 [api|web|all]"
27+
exit 1
28+
;;
29+
esac

0 commit comments

Comments
 (0)