mirror of
https://github.com/commercialhaskell/stackage-server.git
synced 2026-01-21 16:31:56 +01:00
Adds ingress and fixes CI deployment
This commit is contained in:
parent
e0661a0ada
commit
0afe4a7ab5
@ -14,8 +14,12 @@ stages:
|
|||||||
variables:
|
variables:
|
||||||
STACK_ROOT: "${CI_PROJECT_DIR}/.stack-root"
|
STACK_ROOT: "${CI_PROJECT_DIR}/.stack-root"
|
||||||
DEPLOYMENT_IMAGE: "${CI_REGISTRY_IMAGE}:${CI_BUILD_REF_SLUG}_${CI_PIPELINE_ID}"
|
DEPLOYMENT_IMAGE: "${CI_REGISTRY_IMAGE}:${CI_BUILD_REF_SLUG}_${CI_PIPELINE_ID}"
|
||||||
DEPLOYMENT_NAME: "stackage-server-${CI_BUILD_REF_SLUG}"
|
DEPLOYMENT_NAME: "stackage-server-prod"
|
||||||
DEPLOYMENT_APP: "${CI_ENVIRONMENT_SLUG}"
|
HOOGLE_DEPLOYMENT_NAME: "stackage-server-hoogle-prod"
|
||||||
|
CRON_DEPLOYMENT_NAME: "stackage-server-cron-prod"
|
||||||
|
DEPLOYMENT_APP: "stackage-server-prod"
|
||||||
|
CRON_DEPLOYMENT_APP: "stackage-server-cron-prod"
|
||||||
|
HOOGLE_DEPLOYMENT_APP: "stackage-server-hoogle-prod"
|
||||||
|
|
||||||
# This creates anchors for bits of script that are reused between builds
|
# This creates anchors for bits of script that are reused between builds
|
||||||
.anchors:
|
.anchors:
|
||||||
@ -27,8 +31,11 @@ variables:
|
|||||||
kubectl config use-context cluster
|
kubectl config use-context cluster
|
||||||
- &KUBEAPPLY
|
- &KUBEAPPLY
|
||||||
kubectl apply -f <(envsubst <etc/kube/service_template.yaml) &&
|
kubectl apply -f <(envsubst <etc/kube/service_template.yaml) &&
|
||||||
|
kubectl apply -f <(envsubst <etc/kube/hoogle_service_template.yaml) &&
|
||||||
kubectl apply -f <(envsubst <etc/kube/deployment_template.yaml) &&
|
kubectl apply -f <(envsubst <etc/kube/deployment_template.yaml) &&
|
||||||
kubectl rollout status -f <(envsubst <etc/kube/deployment_template.yaml)
|
kubectl apply -f <(envsubst <etc/kube/cron_deployment_template.yaml) &&
|
||||||
|
kubectl apply -f <(envsubst <etc/kube/hoogle_deployment_template.yaml) &&
|
||||||
|
kubectl apply -f <(envsubst <etc/kube/ingress_template.yaml) &&
|
||||||
|
|
||||||
build:
|
build:
|
||||||
stage: build
|
stage: build
|
||||||
@ -60,6 +67,7 @@ deploy_prod:
|
|||||||
HOOGLE_DEPLOYMENT_NAME: "stackage-server-hoogle-prod"
|
HOOGLE_DEPLOYMENT_NAME: "stackage-server-hoogle-prod"
|
||||||
CRON_DEPLOYMENT_NAME: "stackage-server-cron-prod"
|
CRON_DEPLOYMENT_NAME: "stackage-server-cron-prod"
|
||||||
PROD_DEPLOYMENT_IMAGE: "fpco/stackage-server-prod:${CI_BUILD_REF_SLUG}_${CI_PIPELINE_ID}"
|
PROD_DEPLOYMENT_IMAGE: "fpco/stackage-server-prod:${CI_BUILD_REF_SLUG}_${CI_PIPELINE_ID}"
|
||||||
|
HOST: stackage.org
|
||||||
script:
|
script:
|
||||||
- export
|
- export
|
||||||
KUBE_CA_PEM="$PROD_KUBE_CA_PEM"
|
KUBE_CA_PEM="$PROD_KUBE_CA_PEM"
|
||||||
@ -90,11 +98,13 @@ deploy_ci:
|
|||||||
DEPLOYMENT_NAME: "stackage-server-ci"
|
DEPLOYMENT_NAME: "stackage-server-ci"
|
||||||
HOOGLE_DEPLOYMENT_NAME: "stackage-server-hoogle-ci"
|
HOOGLE_DEPLOYMENT_NAME: "stackage-server-hoogle-ci"
|
||||||
CRON_DEPLOYMENT_NAME: "stackage-server-cron-ci"
|
CRON_DEPLOYMENT_NAME: "stackage-server-cron-ci"
|
||||||
|
DEPLOYMENT_APP: "stackage-server-ci"
|
||||||
|
CRON_DEPLOYMENT_APP: "stackage-server-cron-ci"
|
||||||
|
HOOGLE_DEPLOYMENT_APP: "stackage-server-hoogle-ci"
|
||||||
|
HOST: ci.stackage.org
|
||||||
script:
|
script:
|
||||||
- *KUBELOGIN
|
- *KUBELOGIN
|
||||||
- kubectl set image "deployment/$DEPLOYMENT_NAME" stackage-server="$DEPLOYMENT_IMAGE"
|
- *KUBEAPPLY
|
||||||
- kubectl set image "deployment/$HOOGLE_DEPLOYMENT_NAME" stackage-server-hoogle="$DEPLOYMENT_IMAGE"
|
|
||||||
- kubectl set image "deployment/$CRON_DEPLOYMENT_NAME" stackage-server-cron="$DEPLOYMENT_IMAGE"
|
|
||||||
- kubectl rollout status "deployment/$DEPLOYMENT_NAME"
|
- kubectl rollout status "deployment/$DEPLOYMENT_NAME"
|
||||||
- kubectl rollout status "deployment/$HOOGLE_DEPLOYMENT_NAME"
|
- kubectl rollout status "deployment/$HOOGLE_DEPLOYMENT_NAME"
|
||||||
- kubectl rollout status "deployment/$CRON_DEPLOYMENT_NAME"
|
- kubectl rollout status "deployment/$CRON_DEPLOYMENT_NAME"
|
||||||
|
|||||||
61
etc/kube/cron_deployment_template.yaml
Normal file
61
etc/kube/cron_deployment_template.yaml
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
# Kubernetes
|
||||||
|
---
|
||||||
|
apiVersion: extensions/v1beta1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: "${CRON_DEPLOYMENT_NAME}"
|
||||||
|
spec:
|
||||||
|
replicas: 1
|
||||||
|
minReadySeconds: 5
|
||||||
|
strategy:
|
||||||
|
type: Recreate
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: "${CRON_DEPLOYMENT_APP}"
|
||||||
|
spec:
|
||||||
|
volumes:
|
||||||
|
- name: stackage-server-cron-volume
|
||||||
|
secret:
|
||||||
|
secretName: ${CRON_DEPLOYMENT_NAME}-secret
|
||||||
|
containers:
|
||||||
|
- name: stackage-server-cron
|
||||||
|
image: "${DEPLOYMENT_IMAGE}"
|
||||||
|
imagePullPolicy: Always
|
||||||
|
env:
|
||||||
|
- name: PGSTRING
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
name: "${DEPLOYMENT_NAME}"
|
||||||
|
key: PGCONN
|
||||||
|
command:
|
||||||
|
- bash
|
||||||
|
- "-c"
|
||||||
|
- |
|
||||||
|
set -eux
|
||||||
|
source /secret/aws.sh
|
||||||
|
mkdir -p /work
|
||||||
|
cd /work
|
||||||
|
while true
|
||||||
|
do
|
||||||
|
date
|
||||||
|
stack update
|
||||||
|
/usr/local/bin/stackage-server-cron
|
||||||
|
sleep 5m
|
||||||
|
done
|
||||||
|
resources:
|
||||||
|
# NOTE: This differs between prod and ci.
|
||||||
|
# Once we migrate to helm we'll be able to set it
|
||||||
|
# per environment.
|
||||||
|
requests:
|
||||||
|
cpu: 150m
|
||||||
|
memory: 2048Mi
|
||||||
|
limits:
|
||||||
|
cpu: 300m
|
||||||
|
memory: 4096Mi
|
||||||
|
volumeMounts:
|
||||||
|
- name: stackage-server-cron-volume
|
||||||
|
readOnly: true
|
||||||
|
mountPath: /secret
|
||||||
|
imagePullSecrets:
|
||||||
|
- name: registry-key
|
||||||
@ -24,6 +24,11 @@ spec:
|
|||||||
env:
|
env:
|
||||||
- name: APPROOT
|
- name: APPROOT
|
||||||
value: "${APPROOT}"
|
value: "${APPROOT}"
|
||||||
|
- name: PGSTRING
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
name: "${DEPLOYMENT_NAME}"
|
||||||
|
key: PGCONN
|
||||||
readinessProbe:
|
readinessProbe:
|
||||||
httpGet:
|
httpGet:
|
||||||
path: /
|
path: /
|
||||||
@ -44,10 +49,17 @@ spec:
|
|||||||
# Works around stackage-server's `forceSSL` redirect
|
# Works around stackage-server's `forceSSL` redirect
|
||||||
- name: HTTPS
|
- name: HTTPS
|
||||||
value: "on"
|
value: "on"
|
||||||
initialDelaySeconds: 60
|
initialDelaySeconds: 120
|
||||||
timeoutSeconds: 1
|
timeoutSeconds: 1
|
||||||
periodSeconds: 10
|
periodSeconds: 10
|
||||||
successThreshold: 1
|
successThreshold: 1
|
||||||
failureThreshold: 3
|
failureThreshold: 3
|
||||||
|
resources:
|
||||||
|
requests:
|
||||||
|
cpu: 100m
|
||||||
|
memory: 1.0Gi
|
||||||
|
limits:
|
||||||
|
cpu: 150m
|
||||||
|
memory: 1.5Gi
|
||||||
imagePullSecrets:
|
imagePullSecrets:
|
||||||
- name: registry-key
|
- name: registry-key
|
||||||
|
|||||||
65
etc/kube/hoogle_deployment_template.yaml
Normal file
65
etc/kube/hoogle_deployment_template.yaml
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
# Kubernetes
|
||||||
|
---
|
||||||
|
apiVersion: extensions/v1beta1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: "${HOOGLE_DEPLOYMENT_NAME}"
|
||||||
|
spec:
|
||||||
|
replicas: 2
|
||||||
|
minReadySeconds: 5
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: "${HOOGLE_DEPLOYMENT_APP}"
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: stackage-server-hoogle
|
||||||
|
image: "${DEPLOYMENT_IMAGE}"
|
||||||
|
imagePullPolicy: Always
|
||||||
|
ports:
|
||||||
|
- name: http
|
||||||
|
containerPort: 3000
|
||||||
|
command: ["stackage-server"]
|
||||||
|
workingDir: /app
|
||||||
|
env:
|
||||||
|
- name: APPROOT
|
||||||
|
value: "${APPROOT}"
|
||||||
|
- name: PGSTRING
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
name: "${DEPLOYMENT_NAME}"
|
||||||
|
key: PGCONN
|
||||||
|
readinessProbe:
|
||||||
|
httpGet:
|
||||||
|
path: /
|
||||||
|
port: 3000
|
||||||
|
httpHeaders:
|
||||||
|
# Works around stackage-server's `forceSSL` redirect
|
||||||
|
- name: HTTPS
|
||||||
|
value: "on"
|
||||||
|
initialDelaySeconds: 5
|
||||||
|
timeoutSeconds: 1
|
||||||
|
periodSeconds: 5
|
||||||
|
successThreshold: 1
|
||||||
|
livenessProbe:
|
||||||
|
httpGet:
|
||||||
|
path: /
|
||||||
|
port: 3000
|
||||||
|
httpHeaders:
|
||||||
|
# Works around stackage-server's `forceSSL` redirect
|
||||||
|
- name: HTTPS
|
||||||
|
value: "on"
|
||||||
|
initialDelaySeconds: 120
|
||||||
|
timeoutSeconds: 1
|
||||||
|
periodSeconds: 10
|
||||||
|
successThreshold: 1
|
||||||
|
failureThreshold: 3
|
||||||
|
resources:
|
||||||
|
requests:
|
||||||
|
cpu: 100m
|
||||||
|
memory: 1.0Gi
|
||||||
|
limits:
|
||||||
|
cpu: 150m
|
||||||
|
memory: 1.5Gi
|
||||||
|
imagePullSecrets:
|
||||||
|
- name: registry-key
|
||||||
19
etc/kube/hoogle_service_template.yaml
Normal file
19
etc/kube/hoogle_service_template.yaml
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
# Kubernetes
|
||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
name: "${HOOGLE_DEPLOYMENT_NAME}"
|
||||||
|
labels:
|
||||||
|
app: "${HOOGLE_DEPLOYMENT_APP}"
|
||||||
|
spec:
|
||||||
|
ports:
|
||||||
|
- name: http
|
||||||
|
port: 80
|
||||||
|
targetPort: http
|
||||||
|
- name: https
|
||||||
|
port: 443
|
||||||
|
targetPort: http
|
||||||
|
type: ClusterIP
|
||||||
|
selector:
|
||||||
|
app: "${HOOGLE_DEPLOYMENT_APP}"
|
||||||
21
etc/kube/ingress_template.yaml
Normal file
21
etc/kube/ingress_template.yaml
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
apiVersion: extensions/v1beta1
|
||||||
|
kind: Ingress
|
||||||
|
metadata:
|
||||||
|
name: "${DEPLOYMENT_NAME}"
|
||||||
|
labels:
|
||||||
|
app: "${DEPLOYMENT_APP}"
|
||||||
|
annotations:
|
||||||
|
kubernetes.io/ingress.class: "nginx"
|
||||||
|
kubernetes.io/tls-acme: "true"
|
||||||
|
spec:
|
||||||
|
rules:
|
||||||
|
- host: "${HOST}"
|
||||||
|
http:
|
||||||
|
paths:
|
||||||
|
- backend:
|
||||||
|
serviceName: "${DEPLOYMENT_NAME}"
|
||||||
|
servicePort: 80
|
||||||
|
tls:
|
||||||
|
- hosts:
|
||||||
|
- "${HOST}"
|
||||||
|
secretName: "${DEPLOYMENT_NAME}-tls"
|
||||||
Loading…
Reference in New Issue
Block a user