Skip to content

Commit 2de9bbc

Browse files
authored
Merge pull request #8 from crane-cloud/deploy/gcp
chore: deploy to gcp
2 parents 118f657 + 7c65031 commit 2de9bbc

18 files changed

Lines changed: 306 additions & 392 deletions

.env.example

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
FLASK_APP_SECRET=
2+
FLASK_APP_SALT=
3+
JWT_SALT=
24
FLASK_APP=server.py
3-
FLASK_ENV=
5+
FLASK_ENV=development
6+
PRODUCT_BASE_URL=

.github/workflows/prod.yml

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
---
2+
name: Prod
3+
4+
on:
5+
release:
6+
types:
7+
- released
8+
- prereleased
9+
10+
jobs:
11+
build:
12+
outputs:
13+
image: ${{ steps.export.outputs.image }}
14+
tag: ${{ steps.export.outputs.tag }}
15+
16+
runs-on: ubuntu-latest
17+
18+
steps:
19+
- name: Checkout
20+
uses: actions/checkout@v4
21+
with:
22+
ref: master # Reference branch
23+
24+
- name: Install (Buildx)
25+
uses: docker/setup-buildx-action@v3
26+
27+
- name: Login (GCP)
28+
uses: google-github-actions/auth@v2
29+
with:
30+
credentials_json: ${{ secrets.CREDENTIALS_JSON }}
31+
32+
- name: Install (Gcloud)
33+
uses: google-github-actions/setup-gcloud@v1
34+
with:
35+
project_id: crane-cloud-274413
36+
install_components: "gke-gcloud-auth-plugin"
37+
38+
- name: Login (GCR)
39+
run: gcloud auth configure-docker
40+
41+
- id: meta
42+
name: Tag
43+
uses: docker/metadata-action@v3
44+
with:
45+
flavor: |
46+
latest=true
47+
images: gcr.io/crane-cloud-274413/monitoring-api
48+
tags: |
49+
type=ref,event=branch
50+
type=ref,event=pr
51+
type=semver,pattern={{version}}
52+
type=semver,pattern={{major}}.{{minor}}
53+
type=sha
54+
55+
- name: Build
56+
uses: docker/build-push-action@v2
57+
with:
58+
cache-from: type=gha
59+
cache-to: type=gha,mode=max
60+
context: .
61+
file: docker/prod/Dockerfile
62+
labels: ${{ steps.meta.outputs.labels }}
63+
push: true
64+
tags: ${{ steps.meta.outputs.tags }}
65+
66+
- id: export
67+
name: Export
68+
uses: actions/github-script@v5
69+
with:
70+
script: |
71+
const metadata = JSON.parse(`${{ steps.meta.outputs.json }}`)
72+
const fullUrl = metadata.tags.find((t) => t.includes(':sha-'))
73+
if (fullUrl == null) {
74+
core.error('Unable to find sha tag of image')
75+
} else {
76+
const tag = fullUrl.split(':')[1]
77+
core.setOutput('image', fullUrl)
78+
core.setOutput('tag', tag)
79+
}
80+
81+
Production:
82+
name: Deploy (Production)
83+
84+
needs:
85+
- build
86+
87+
runs-on: ubuntu-latest
88+
89+
env:
90+
namespace: cranecloud-prod
91+
92+
steps:
93+
- name: Clone
94+
uses: actions/checkout@v2
95+
96+
- name: Login (GCP)
97+
uses: google-github-actions/auth@v2
98+
with:
99+
credentials_json: ${{ secrets.CREDENTIALS_JSON }}
100+
101+
- name: Install (Gcloud)
102+
uses: google-github-actions/setup-gcloud@v1
103+
with:
104+
project_id: crane-cloud-274413
105+
install_components: "gke-gcloud-auth-plugin"
106+
107+
- name: Login (Kubernetes Cluster)
108+
uses: google-github-actions/get-gke-credentials@v1
109+
with:
110+
cluster_name: staging-cluster
111+
location: us-central1-a
112+
project_id: crane-cloud-274413
113+
114+
- name: Add Repo (cranecloud)
115+
run: |
116+
helm repo add cranecloud https://crane-cloud.github.io/helm-charts/
117+
118+
- name: Helm Release
119+
run: |
120+
helm upgrade --install \
121+
monitoring-api cranecloud/cranecloud \
122+
--values helm/values.prod.yaml \
123+
--namespace $namespace \
124+
--set image.tag="${{ needs.build.outputs.tag }}" \
125+
--set environment.DATABASE_URI="${{ secrets.PRODUCTION_DATABASE_URI }}" \
126+
--set environment.DATABASE_USER="${{ secrets.PRODUCTION_DATABASE_USER }}" \
127+
--set environment.TEST_DATABASE_URL="${{ secrets.PRODUCTION_TEST_DATABASE_URL }}" \
128+
--set environment.FLASK_APP_SALT="${{ secrets.PRODUCTION_JWT_SALT }}" \
129+
--set environment.FLASK_APP_SECRET="${{ secrets.PRODUCTION_JWT_SALT }}" \
130+
--set environment.PRODUCT_BASE_URL="${{ secrets.PRODUCTION_PRODUCT_BASE_URL }}" \
131+
--set environment.LOGGER_APP_URL="${{ secrets.PRODUCTION_LOGGER_APP_URL }}" \
132+
--timeout=300s
133+
134+
- name: Monitor Rollout
135+
run: |
136+
kubectl rollout status deployment/monitoring-api --timeout=300s --namespace $namespace

.github/workflows/staging.yml

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,25 +72,47 @@ jobs:
7272
name: Deploy (Staging)
7373

7474
needs:
75-
- Build
75+
- build
7676

7777
runs-on: ubuntu-latest
7878
env:
79-
namespace: cranecloud-microservice
79+
namespace: cranecloud
8080
image: cranecloud/monitoring-api
8181

8282
steps:
8383
- name: Checkout code
8484
uses: actions/checkout@v2
8585

86-
- uses: azure/k8s-set-context@v1
86+
# - uses: azure/k8s-set-context@v1
87+
# with:
88+
# kubeconfig: ${{ secrets.RENU_KUBECONFIG}}
89+
90+
- name: Login (GCP)
91+
uses: google-github-actions/auth@v0
92+
with:
93+
credentials_json: ${{ secrets.CREDENTIALS_JSON }}
94+
95+
- name: Install (Gcloud)
96+
uses: google-github-actions/setup-gcloud@v1
8797
with:
88-
kubeconfig: ${{ secrets.RENU_KUBECONFIG}}
98+
project_id: crane-cloud-274413
99+
install_components: "gke-gcloud-auth-plugin"
100+
101+
- name: Login (Kubernetes Cluster)
102+
uses: google-github-actions/get-gke-credentials@v1
103+
with:
104+
cluster_name: staging-cluster
105+
location: us-central1-a
106+
project_id: crane-cloud-274413
107+
108+
- name: Add Repo (cranecloud)
109+
run: |
110+
helm repo add cranecloud https://crane-cloud.github.io/helm-charts/
89111
90112
- name: Helm Release
91113
run: |
92114
helm upgrade --install --create-namespace \
93-
monitoring-api ./helm/chart \
115+
monitoring-api cranecloud/cranecloud \
94116
--values helm/values.staging.yaml \
95117
--namespace $namespace \
96118
--set image.tag="${{ needs.build.outputs.tag }}" \

ReadMe.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Crane Cloud Monitoring API
2+
[![Prod](https://github.com/crane-cloud/monitoring-api/actions/workflows/prod.yml/badge.svg)](https://github.com/crane-cloud/monitoring-api/actions/workflows/prod.yml)
3+
[![staging](https://github.com/crane-cloud/monitoring-api/actions/workflows/staging.yml/badge.svg)](https://github.com/crane-cloud/monitoring-api/actions/workflows/staging.yml)
4+
5+
The Crane Cloud Monitoring API provides a backend service for monitoring resource usage (CPU, memory, network) within a Kubernetes environment. It interfaces with Prometheus to fetch and aggregate metrics data.
6+
7+
## Features
8+
9+
- RESTful API endpoints to fetch metrics for projects and applications.
10+
- Integration with Prometheus for metrics collection.
11+
- Docker containerization for easy deployment and scaling.
12+
- Helm charts for Kubernetes deployments.
13+
14+
## Prerequisites
15+
16+
- Docker and Docker Compose
17+
- Python 3.10
18+
- Helm 3 for Kubernetes deployment
19+
- Access to a Kubernetes cluster (for staging/production environments)
20+
21+
## Local Development Setup
22+
23+
1. **Clone the repository:**
24+
25+
```bash
26+
git clone https://github.com/crane-cloud/monitoring-api.git
27+
cd monitoring-api
28+
```
29+
30+
2. **Environment Variables:**
31+
32+
Copy the `.env.example` to `.env` and modify the environment variables according to your local setup.
33+
34+
3. **Start the application:**
35+
36+
Use Docker Compose to build and run the local development environment:
37+
38+
```bash
39+
make start
40+
```
41+
42+
This command builds the Docker image and starts the services defined in `docker-compose.yml`.
43+
44+
## API Documentation
45+
46+
Swagger documentation is available once the application is running, accessible at `/apidocs`.

docker/prod/Dockerfile

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# use an official python runtime as the base image
2+
FROM python:3.10
3+
4+
# set the (container) working directory
5+
WORKDIR /app
6+
7+
8+
# install netcat
9+
RUN apt-get update && \
10+
apt-get install netcat-traditional -y
11+
12+
COPY requirements.txt /app/requirements.txt
13+
14+
15+
# install dependencies
16+
RUN pip install -r requirements.txt
17+
18+
# copy current (local) directory contents into the container
19+
COPY . /app
20+
21+
22+
# make port available to the world outside this container
23+
EXPOSE 5000
24+
25+
# connect to start script when db is being used
26+
ENTRYPOINT ["sh", "/app/scripts/start-prod.sh"]

helm/chart/.helmignore

Lines changed: 0 additions & 23 deletions
This file was deleted.

helm/chart/Chart.yaml

Lines changed: 0 additions & 23 deletions
This file was deleted.

helm/chart/templates/_helpers.tpl

Lines changed: 0 additions & 47 deletions
This file was deleted.

0 commit comments

Comments
 (0)