Add K8s deployment for OCI (aarch64) and make deploy/deploy-oci targets
- K8s manifests: namespace, PVC (local-path 2Gi), deployment, service, ingress - Ingress: repo-vis.oci.euphon.net with Let's Encrypt TLS via traefik - Cross-compile aarch64-unknown-linux-musl for OCI ARM64 host - make deploy: local Docker (x86_64) - make deploy-oci: SCP binary + web dist to OCI, native docker build, k3s import - Dockerfile accepts MUSL_TARGET build arg for multi-arch support
This commit is contained in:
parent
4aec9510e4
commit
0be0652a49
@ -1,12 +1,12 @@
|
|||||||
# Keep the musl release binary, ignore the rest
|
# Keep musl release binaries, ignore build artifacts
|
||||||
server/target/debug
|
server/target/debug
|
||||||
server/target/release
|
server/target/release
|
||||||
server/target/x86_64-unknown-linux-musl/debug
|
server/target/*/debug
|
||||||
server/target/x86_64-unknown-linux-musl/release/build
|
server/target/*/release/build
|
||||||
server/target/x86_64-unknown-linux-musl/release/deps
|
server/target/*/release/deps
|
||||||
server/target/x86_64-unknown-linux-musl/release/.fingerprint
|
server/target/*/release/.fingerprint
|
||||||
server/target/x86_64-unknown-linux-musl/release/incremental
|
server/target/*/release/incremental
|
||||||
server/target/x86_64-unknown-linux-musl/release/examples
|
server/target/*/release/examples
|
||||||
web/node_modules
|
web/node_modules
|
||||||
web/dist
|
web/dist
|
||||||
*.db
|
*.db
|
||||||
|
|||||||
@ -11,7 +11,8 @@ FROM alpine:3.21
|
|||||||
RUN apk add --no-cache git ca-certificates
|
RUN apk add --no-cache git ca-certificates
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY server/target/x86_64-unknown-linux-musl/release/repo-vis-server ./
|
ARG MUSL_TARGET=x86_64-unknown-linux-musl
|
||||||
|
COPY server/target/${MUSL_TARGET}/release/repo-vis-server ./
|
||||||
COPY --from=frontend /build/dist ./web/dist/
|
COPY --from=frontend /build/dist ./web/dist/
|
||||||
|
|
||||||
ENV PORT=8080
|
ENV PORT=8080
|
||||||
|
|||||||
50
Makefile
50
Makefile
@ -1,22 +1,29 @@
|
|||||||
.PHONY: build-server build-web build deploy clean
|
.PHONY: build-server build-web build deploy deploy-oci clean
|
||||||
|
|
||||||
MUSL_TARGET := x86_64-unknown-linux-musl
|
MUSL_TARGET_X86 := x86_64-unknown-linux-musl
|
||||||
|
MUSL_TARGET_ARM := aarch64-unknown-linux-musl
|
||||||
CONTAINER := repo-vis
|
CONTAINER := repo-vis
|
||||||
IMAGE := repo-vis:latest
|
IMAGE := repo-vis:latest
|
||||||
PORT := 9120
|
PORT := 9120
|
||||||
|
OCI_HOST := oci.euphon.net
|
||||||
|
|
||||||
build-server:
|
build-server-x86:
|
||||||
cd server && cargo build --release --target $(MUSL_TARGET)
|
cd server && cargo build --release --target $(MUSL_TARGET_X86)
|
||||||
|
|
||||||
|
build-server-arm:
|
||||||
|
cd server && cargo build --release --target $(MUSL_TARGET_ARM)
|
||||||
|
|
||||||
build-web:
|
build-web:
|
||||||
cd web && npm run build
|
cd web && npm run build
|
||||||
|
|
||||||
build: build-server build-web
|
build: build-server-x86 build-web
|
||||||
|
build-arm: build-server-arm build-web
|
||||||
|
|
||||||
|
# --- Local Docker deploy (x86_64) ---
|
||||||
deploy: build
|
deploy: build
|
||||||
-docker stop $(CONTAINER) 2>/dev/null
|
-docker stop $(CONTAINER) 2>/dev/null
|
||||||
-docker rm $(CONTAINER) 2>/dev/null
|
-docker rm $(CONTAINER) 2>/dev/null
|
||||||
docker build -t $(IMAGE) .
|
docker build --build-arg MUSL_TARGET=$(MUSL_TARGET_X86) -t $(IMAGE) .
|
||||||
docker run -d \
|
docker run -d \
|
||||||
--name $(CONTAINER) \
|
--name $(CONTAINER) \
|
||||||
-p $(PORT):8080 \
|
-p $(PORT):8080 \
|
||||||
@ -25,6 +32,37 @@ deploy: build
|
|||||||
$(IMAGE)
|
$(IMAGE)
|
||||||
@echo "repo-vis running at http://localhost:$(PORT)"
|
@echo "repo-vis running at http://localhost:$(PORT)"
|
||||||
|
|
||||||
|
# --- OCI K8s deploy (aarch64, native build on OCI) ---
|
||||||
|
OCI_TMP = /tmp/repo-vis-deploy
|
||||||
|
deploy-oci: build-arm
|
||||||
|
@echo "==> Uploading to OCI..."
|
||||||
|
ssh $(OCI_HOST) "rm -rf $(OCI_TMP) && mkdir -p $(OCI_TMP)"
|
||||||
|
scp server/target/$(MUSL_TARGET_ARM)/release/repo-vis-server $(OCI_HOST):$(OCI_TMP)/
|
||||||
|
cd web && tar czf /tmp/_rv_dist.tar.gz dist && scp /tmp/_rv_dist.tar.gz $(OCI_HOST):$(OCI_TMP)/
|
||||||
|
@echo "==> Building image on OCI..."
|
||||||
|
ssh $(OCI_HOST) 'cd $(OCI_TMP) && tar xzf _rv_dist.tar.gz && cat > Dockerfile <<DEOF\n\
|
||||||
|
FROM alpine:3.21\n\
|
||||||
|
RUN apk add --no-cache git ca-certificates\n\
|
||||||
|
WORKDIR /app\n\
|
||||||
|
COPY repo-vis-server ./\n\
|
||||||
|
COPY dist ./web/dist/\n\
|
||||||
|
ENV PORT=8080\n\
|
||||||
|
ENV FRONTEND_DIR=./web/dist\n\
|
||||||
|
EXPOSE 8080\n\
|
||||||
|
CMD ["./repo-vis-server"]\n\
|
||||||
|
DEOF\n\
|
||||||
|
sudo docker build -t repo-vis:latest . && \
|
||||||
|
sudo docker save repo-vis:latest -o /tmp/_rv.tar && \
|
||||||
|
sudo k3s ctr images import /tmp/_rv.tar'
|
||||||
|
@echo "==> Applying K8s manifests..."
|
||||||
|
ssh $(OCI_HOST) "kubectl apply -f -" < k8s/namespace.yaml
|
||||||
|
ssh $(OCI_HOST) "kubectl apply -f -" < k8s/pvc.yaml
|
||||||
|
ssh $(OCI_HOST) "kubectl apply -f -" < k8s/deployment.yaml
|
||||||
|
ssh $(OCI_HOST) "kubectl apply -f -" < k8s/service.yaml
|
||||||
|
ssh $(OCI_HOST) "kubectl apply -f -" < k8s/ingress.yaml
|
||||||
|
ssh $(OCI_HOST) "kubectl -n repo-vis rollout restart deployment/repo-vis"
|
||||||
|
@echo "==> Deployed to https://repo-vis.oci.euphon.net"
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
cd server && cargo clean
|
cd server && cargo clean
|
||||||
rm -rf web/dist
|
rm -rf web/dist
|
||||||
|
|||||||
35
k8s/deployment.yaml
Normal file
35
k8s/deployment.yaml
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: repo-vis
|
||||||
|
namespace: repo-vis
|
||||||
|
spec:
|
||||||
|
replicas: 1
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
app: repo-vis
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: repo-vis
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: repo-vis
|
||||||
|
image: repo-vis:latest
|
||||||
|
imagePullPolicy: Never
|
||||||
|
ports:
|
||||||
|
- containerPort: 8080
|
||||||
|
env:
|
||||||
|
- name: PORT
|
||||||
|
value: "8080"
|
||||||
|
- name: FRONTEND_DIR
|
||||||
|
value: "./web/dist"
|
||||||
|
- name: DATA_DIR
|
||||||
|
value: "/data"
|
||||||
|
volumeMounts:
|
||||||
|
- name: data
|
||||||
|
mountPath: /data
|
||||||
|
volumes:
|
||||||
|
- name: data
|
||||||
|
persistentVolumeClaim:
|
||||||
|
claimName: repo-vis-data
|
||||||
23
k8s/ingress.yaml
Normal file
23
k8s/ingress.yaml
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
apiVersion: networking.k8s.io/v1
|
||||||
|
kind: Ingress
|
||||||
|
metadata:
|
||||||
|
name: repo-vis
|
||||||
|
namespace: repo-vis
|
||||||
|
annotations:
|
||||||
|
traefik.ingress.kubernetes.io/router.tls.certresolver: le
|
||||||
|
spec:
|
||||||
|
ingressClassName: traefik
|
||||||
|
rules:
|
||||||
|
- host: repo-vis.oci.euphon.net
|
||||||
|
http:
|
||||||
|
paths:
|
||||||
|
- path: /
|
||||||
|
pathType: Prefix
|
||||||
|
backend:
|
||||||
|
service:
|
||||||
|
name: repo-vis
|
||||||
|
port:
|
||||||
|
number: 80
|
||||||
|
tls:
|
||||||
|
- hosts:
|
||||||
|
- repo-vis.oci.euphon.net
|
||||||
4
k8s/namespace.yaml
Normal file
4
k8s/namespace.yaml
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
apiVersion: v1
|
||||||
|
kind: Namespace
|
||||||
|
metadata:
|
||||||
|
name: repo-vis
|
||||||
11
k8s/pvc.yaml
Normal file
11
k8s/pvc.yaml
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
apiVersion: v1
|
||||||
|
kind: PersistentVolumeClaim
|
||||||
|
metadata:
|
||||||
|
name: repo-vis-data
|
||||||
|
namespace: repo-vis
|
||||||
|
spec:
|
||||||
|
accessModes:
|
||||||
|
- ReadWriteOnce
|
||||||
|
resources:
|
||||||
|
requests:
|
||||||
|
storage: 2Gi
|
||||||
11
k8s/service.yaml
Normal file
11
k8s/service.yaml
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
name: repo-vis
|
||||||
|
namespace: repo-vis
|
||||||
|
spec:
|
||||||
|
selector:
|
||||||
|
app: repo-vis
|
||||||
|
ports:
|
||||||
|
- port: 80
|
||||||
|
targetPort: 8080
|
||||||
2
server/.cargo/config.toml
Normal file
2
server/.cargo/config.toml
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
[target.aarch64-unknown-linux-musl]
|
||||||
|
linker = "aarch64-linux-gnu-gcc"
|
||||||
Loading…
x
Reference in New Issue
Block a user