Skip to content

Commit

Permalink
Merge pull request #271 from alercebroker/feature/alerts-api-deploy
Browse files Browse the repository at this point in the history
Feature/alerts api deploy
  • Loading branch information
edipizarro authored Mar 18, 2024
2 parents 9d6f879 + b9154cd commit 8cb4cf3
Show file tree
Hide file tree
Showing 150 changed files with 503 additions and 25 deletions.
14 changes: 7 additions & 7 deletions ztf_api/Dockerfile → alerts-api/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ FROM python-base as builder
ARG WITH_ENV
RUN pip install poetry
WORKDIR /app
COPY ./poetry.lock ./pyproject.toml ./
COPY ./alerts-api/poetry.lock ./alerts-api/pyproject.toml ./
RUN poetry install --no-root --without=dev --without=test


Expand All @@ -26,11 +26,11 @@ ENV APP_WORKERS="1"
ENV ENVIRONMENT="production"
ENV SERVER_SOFTWARE="gunicorn"
ENV PROMETHEUS_MULTIPROC_DIR="/tmp"
COPY ./README.md /app/README.md
COPY ./description.md /app/description.md
COPY ./gunicorn_config.py /app/gunicorn_config.py
COPY ./config.yml /app/config.yml
COPY ./scripts /app/scripts
COPY ./src /app/src
COPY ./alerts-api/README.md /app/README.md
COPY ./alerts-api/description.md /app/description.md
COPY ./alerts-api/gunicorn_config.py /app/gunicorn_config.py
COPY ./alerts-api/config.yml /app/config.yml
COPY ./alerts-api/scripts /app/scripts
COPY ./alerts-api/src /app/src
RUN poetry install --only-root
CMD ["/bin/bash","scripts/entrypoint.sh"]
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions ztf_api/README.md → alerts-api/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
![](https://github.com/alercebroker/ztf-api-new/workflows/Tests/badge.svg)
![](https://github.com/alercebroker/ztf_api-new/workflows/Tests/badge.svg)
[![codecov](https://codecov.io/gh/alercebroker/ztf_api/branch/master/graph/badge.svg?token=UHM0AV87S5)](https://codecov.io/gh/alercebroker/ztf_api)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![pyVersion38](https://img.shields.io/badge/python-3.8-blue.svg)](https://www.python.org/download/releases/3.8/)
Expand All @@ -11,7 +11,7 @@

## For developers

Clone this repo using `git clone https://github.com/alercebroker/ztf-api.git` and install requirements with `pip install -r requirements.txt`.
Clone this repo using `git clone https://github.com/alercebroker/ztf_api.git` and install requirements with `pip install -r requirements.txt`.

For modify an existing endpoint, go to `api/resources` and enter the folder of the endpoint that you want to modify. Only write code to specific task of this endpoint.

Expand Down
10 changes: 5 additions & 5 deletions ztf_api/config.yml → alerts-api/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ PROFILE_CONFIG:
- "^/static/.*"
DATABASE:
SQL:
HOST: ${DB_HOST}
DATABASE: ${DB_DATABASE}
USER: ${DB_USER}
PASSWORD: ${DB_PASSWORD}
PORT: ${DB_PORT}
HOST: ${PSQL_HOST}
DATABASE: ${PSQL_DATABASE}
USER: ${PSQL_USER}
PASSWORD: ${PSQL_PASSWORD}
PORT: ${PSQL_PORT}
MONGO:
HOST: ${MONGO_HOST}
USERNAME: ${MONGO_USER}
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ services:
- 5001:5001
environment:
- PORT=5001
- DB_HOST=postgres
- DB_DATABASE=postgres
- DB_USER=postgres
- DB_PASSWORD=postgres
- DB_PORT=5432
- PSQL_HOST=postgres
- PSQL_DATABASE=postgres
- PSQL_USER=postgres
- PSQL_PASSWORD=postgres
- PSQL_PORT=5432
- MONGO_HOST=mongo
- MONGO_DATABASE=database
- MONGO_AUTH_SOURCE=database
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion ztf_api/pyproject.toml → alerts-api/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ line-length = 79

[tool.poetry]
name = "alerts-api"
version = "1.3.1a41"
version = "23.12.1-rc8"
description = "AlertsAPI"
authors = ["ALeRCE"]
readme = "README.md"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ services:
- 5001:5001
environment:
- PORT=5001
- DB_HOST=postgres
- DB_DATABASE=postgres
- DB_USER=postgres
- DB_PASSWORD=postgres
- DB_PORT=5432
- PSQL_HOST=postgres
- PSQL_DATABASE=postgres
- PSQL_USER=postgres
- PSQL_PASSWORD=postgres
- PSQL_PORT=5432
- MONGO_HOST=mongo
- MONGO_DATABASE=database
- MONGO_AUTH_SOURCE=database
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
23 changes: 23 additions & 0 deletions charts/alerts-api/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
6 changes: 6 additions & 0 deletions charts/alerts-api/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: v1
appVersion: 23.12.1-rc8
description: ALeRCE API
name: alerts-api
type: application
version: 23.12.8
68 changes: 68 additions & 0 deletions charts/alerts-api/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "alerts-api.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "alerts-api.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Chart.Name .Values.nameOverride }}
{{- if contains $name .Release.Name }}
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}
{{- end }}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "alerts-api.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "alerts-api.labels" -}}
helm.sh/chart: {{ include "alerts-api.chart" . }}
{{ include "alerts-api.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "alerts-api.selectorLabels" -}}
app.kubernetes.io/name: {{ include "alerts-api.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{/*
Create the name of the service account to use
*/}}
{{- define "alerts-api.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "alerts-api.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}

{{- define "imagePullSecret" }}
{{- with .Values.imageCredentials }}
{{- printf "{\"auths\":{\"%s\":{\"username\":\"%s\",\"password\":\"%s\",\"email\":\"%s\",\"auth\":\"%s\"}}}" .registry .username .password .email (printf "%s:%s" .username .password | b64enc) | b64enc }}
{{- end }}
{{- end }}
43 changes: 43 additions & 0 deletions charts/alerts-api/templates/configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "alerts-api.fullname" . }}
namespace: {{ .Values.namespace }}
data:
port: '{{ .Values.configmap.port }}'
api-url: '{{ .Values.configmap.apiUrl }}'
app-workers: '{{ .Values.configmap.appWorkers }}'
threads: '{{ .Values.configmap.threads }}'
log-level: '{{ .Values.configmap.logLevel }}'
---
apiVersion: v1
metadata:
name: alerts-api-nginx-conf
namespace: {{ .Values.namespace }}
data:
default.conf: |
server {
listen 80;
location /v1/alerts/ {
proxy_pass http://localhost:5000/;
proxy_redirect off;
proxy_set_header X-Forwarded-Prefix /v1/alerts/;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Host $http_host;
}
location /v1/alerts {
proxy_pass http://localhost:5000/;
proxy_redirect off;
proxy_set_header X-Forwarded-Prefix /v1/alerts;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Host $http_host;
}
location / {
proxy_pass http://localhost:5000/;
}
}
kind: ConfigMap
142 changes: 142 additions & 0 deletions charts/alerts-api/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "alerts-api.fullname" . }}
namespace: {{ .Values.namespace }}
labels:
{{- include "alerts-api.labels" . | nindent 4 }}
spec:
{{- if not .Values.autoscaling.enabled }}
replicas: {{ .Values.replicaCount }}
{{- end }}
selector:
matchLabels:
{{- include "alerts-api.selectorLabels" . | nindent 6 }}
template:
metadata:
{{- with .Values.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "alerts-api.selectorLabels" . | nindent 8 }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
containers:
- name: {{ .Chart.Name }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
resources:
{{- toYaml .Values.resources | nindent 12 }}
env:
- name: PORT
valueFrom:
configMapKeyRef:
name: {{ include "alerts-api.fullname" . }}
key: port
- name: API_URL
valueFrom:
configMapKeyRef:
name: {{ include "alerts-api.fullname" . }}
key: api-url
- name: APP_WORKERS
valueFrom:
configMapKeyRef:
name: {{ include "alerts-api.fullname" . }}
key: app-workers
- name: THREADS
valueFrom:
configMapKeyRef:
name: {{ include "alerts-api.fullname" . }}
key: threads
- name: LOG_LEVEL
valueFrom:
configMapKeyRef:
name: {{ include "alerts-api.fullname" . }}
key: log-level
- name: PSQL_HOST
valueFrom:
secretKeyRef:
name: database-auth
key: sql-host
- name: PSQL_DATABASE
valueFrom:
secretKeyRef:
name: database-auth
key: sql-database
- name: PSQL_USER
valueFrom:
secretKeyRef:
name: database-auth
key: sql-user
- name: PSQL_PASSWORD
valueFrom:
secretKeyRef:
name: database-auth
key: sql-password
- name: PSQL_PORT
valueFrom:
secretKeyRef:
name: database-auth
key: sql-port
- name: MONGO_HOST
valueFrom:
secretKeyRef:
name: database-auth
key: mongo-host
- name: MONGO_DATABASE
valueFrom:
secretKeyRef:
name: database-auth
key: mongo-database
- name: MONGO_AUTH_SOURCE
valueFrom:
secretKeyRef:
name: database-auth
key: mongo-auth-source
- name: MONGO_USER
valueFrom:
secretKeyRef:
name: database-auth
key: mongo-user
- name: MONGO_PASSWORD
valueFrom:
secretKeyRef:
name: database-auth
key: mongo-password
- name: MONGO_PORT
valueFrom:
secretKeyRef:
name: database-auth
key: mongo-port
- name: SECRET_KEY
valueFrom:
secretKeyRef:
name: secret-key
key: secret-key
- name: nginx-sidecar
image: nginx
ports:
- containerPort: 80
volumeMounts:
- name: nginx-conf
mountPath: /etc/nginx/conf.d/default.conf
subPath: default.conf
resources:
requests:
memory: 64M
cpu: 50m
volumes:
- name: nginx-conf
configMap:
name: alerts-api-nginx-conf
items:
- key: "default.conf"
path: "default.conf"
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
Loading

0 comments on commit 8cb4cf3

Please sign in to comment.