Skip to content

Commit a55dcde

Browse files
authored
Merge pull request #27 from crane-cloud/develop
Update Master
2 parents 7f29ce5 + 7c9430e commit a55dcde

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+4611
-805
lines changed

.coveragerc

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[run]
2+
relative_files = True
3+
4+
[report]
5+
exclude_lines =
6+
pragma: no cover
7+
@abstract
8+
def __init__

.coveralls.yml

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
repo_token: gfzn9dLO4qLegQH3tdalqrEMK78ZRkOXW

.dockerignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ venv/
44
*.pyc
55
.coverage
66
.vscode/
7-
docker/
7+
# docker/

.github/workflows/prod.yml

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

.github/workflows/staging.yaml

+131
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
---
2+
name: staging
3+
4+
on:
5+
push:
6+
branches:
7+
- develop
8+
9+
workflow_dispatch:
10+
11+
jobs:
12+
build:
13+
outputs:
14+
image: ${{ steps.export.outputs.image }}
15+
tag: ${{ steps.export.outputs.tag }}
16+
17+
runs-on: ubuntu-latest
18+
env:
19+
image: cranecloud/database-api
20+
21+
steps:
22+
- name: Checkout
23+
uses: actions/checkout@v2
24+
25+
- name: Install (Buildx)
26+
uses: docker/setup-buildx-action@v1
27+
28+
- name: Login to Docker Hub
29+
uses: docker/login-action@v2
30+
with:
31+
username: ${{ secrets.DOCKERHUB_USERNAME }}
32+
password: ${{ secrets.DOCKERHUB_TOKEN }}
33+
34+
- id: meta
35+
name: Tag
36+
uses: docker/metadata-action@v3
37+
with:
38+
flavor: |
39+
latest=true
40+
images: ${{ env.image }}
41+
tags: |
42+
type=ref,event=branch
43+
type=ref,event=pr
44+
type=sha
45+
46+
- name: Build
47+
uses: docker/build-push-action@v2
48+
with:
49+
cache-from: type=gha
50+
cache-to: type=gha,mode=max
51+
context: .
52+
file: Dockerfile
53+
labels: ${{ steps.meta.outputs.labels }}
54+
push: true
55+
tags: ${{ steps.meta.outputs.tags }}
56+
57+
- id: export
58+
name: Export
59+
uses: actions/github-script@v5
60+
with:
61+
script: |
62+
const metadata = JSON.parse(`${{ steps.meta.outputs.json }}`)
63+
const fullUrl = metadata.tags.find((t) => t.includes(':sha-'))
64+
if (fullUrl == null) {
65+
core.error('Unable to find sha tag of image')
66+
} else {
67+
const tag = fullUrl.split(':')[1]
68+
core.setOutput('image', fullUrl)
69+
core.setOutput('tag', tag)
70+
}
71+
72+
Staging:
73+
name: Deploy (Staging)
74+
75+
needs:
76+
- build
77+
78+
runs-on: ubuntu-latest
79+
env:
80+
namespace: cranecloud
81+
image: cranecloud/database-api
82+
83+
steps:
84+
- name: Checkout code
85+
uses: actions/checkout@v4
86+
87+
- name: Login (GCP)
88+
uses: google-github-actions/auth@v2
89+
with:
90+
credentials_json: ${{ secrets.CREDENTIALS_JSON }}
91+
92+
- name: Install (Gcloud)
93+
uses: google-github-actions/setup-gcloud@v2
94+
with:
95+
project_id: crane-cloud-274413
96+
install_components: "gke-gcloud-auth-plugin"
97+
98+
- name: Login (Kubernetes Cluster)
99+
uses: google-github-actions/get-gke-credentials@v2
100+
with:
101+
cluster_name: staging-cluster
102+
location: us-central1-a
103+
project_id: crane-cloud-274413
104+
105+
- name: Add Repo (cranecloud)
106+
run: |
107+
helm repo add cranecloud https://crane-cloud.github.io/helm-charts/
108+
109+
- name: Helm Release
110+
run: |
111+
helm upgrade --install \
112+
database-api cranecloud/cranecloud \
113+
--values helm/values.staging.yaml \
114+
--namespace $namespace \
115+
--set image.tag="${{ needs.build.outputs.tag }}" \
116+
--set environment.DATABASE_URI="${{ secrets.STAGING_DATABASE_URI }}" \
117+
--set environment.JWT_SALT="${{ secrets.STAGING_JWT_SALT }}" \
118+
--set environment.ACTIVITY_LOGGER_URL="${{ secrets.STAGING_ACTIVITY_LOGGER_URL }}" \
119+
--set environment.ADMIN_MYSQL_USER="${{ secrets.STAGING_ADMIN_MYSQL_USER }}" \
120+
--set environment.ADMIN_MYSQL_PASSWORD="${{ secrets.STAGING_ADMIN_MYSQL_PASSWORD }}" \
121+
--set environment.ADMIN_MYSQL_HOST="${{ secrets.STAGING_ADMIN_MYSQL_HOST }}" \
122+
--set environment.ADMIN_MYSQL_PORT="${{ secrets.STAGING_ADMIN_MYSQL_PORT }}" \
123+
--set environment.ADMIN_PSQL_USER="${{ secrets.STAGING_ADMIN_PSQL_USER }}" \
124+
--set environment.ADMIN_PSQL_PASSWORD="${{ secrets.STAGING_ADMIN_PSQL_PASSWORD }}" \
125+
--set environment.ADMIN_PSQL_HOST="${{ secrets.STAGING_ADMIN_PSQL_HOST }}" \
126+
--set environment.ADMIN_PSQL_PORT="${{ secrets.STAGING_ADMIN_PSQL_PORT }}" \
127+
--timeout=300s
128+
129+
- name: Monitor Rollout
130+
run: |
131+
kubectl rollout status deployment/database-api --timeout=300s --namespace $namespace

.github/workflows/testing.yaml

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Test
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
build:
9+
runs-on: ubuntu-20.04
10+
env:
11+
FASTAPI_ENV: testing
12+
13+
strategy:
14+
matrix:
15+
python-version: ["3.10"]
16+
17+
steps:
18+
- uses: actions/checkout@v2
19+
20+
- name: Set up Python ${{ matrix.python-version }}
21+
uses: actions/setup-python@v2
22+
with:
23+
python-version: ${{ matrix.python-version }}
24+
25+
- name: Test with pytest
26+
run: |
27+
make test

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ venv/
88
.DS_Store
99
.idea/
1010
.pytest_cache/
11+
.env.bat

Dockerfile

+6-8
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,18 @@ ENV DEBIAN_FRONTEND='noninteractive'
66

77
RUN apt-get update && apt install -y curl
88

9+
COPY ./README.md /app/README.md
10+
911
RUN pip install poetry
1012

1113
ENV PATH="${PATH}:/root/.local/bin"
1214

13-
COPY ./pyproject.toml /app/pyproject.toml
14-
15-
COPY ./poetry.lock /app/poetry.lock
16-
15+
COPY . /app
1716

1817
RUN poetry install
1918

20-
COPY . /app
21-
2219
EXPOSE 8000
2320

24-
CMD ["poetry", "run", "uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000", "--reload"]
25-
21+
#Exposing port for celery flower
22+
# EXPOSE 5555
23+
ENTRYPOINT ["sh", "/app/scripts/start.sh"]

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
# Database API
2+
[![Coverage Status](https://coveralls.io/repos/github/crane-cloud/database-api/badge.svg?branch=develop)](https://coveralls.io/github/crane-cloud/database-api?branch=develop)
3+
[![Prod](https://github.com/crane-cloud/database-api/actions/workflows/prod.yml/badge.svg)](https://github.com/crane-cloud/database-api/actions/workflows/prod.yml)
4+
[![staging](https://github.com/crane-cloud/database-api/actions/workflows/staging.yaml/badge.svg)](https://github.com/crane-cloud/database-api/actions/workflows/staging.yaml)
25

36
The database API offers a convenient and efficient way to create MySQL and PostgreSQL databases for users on the Crane Cloud platform
47

@@ -7,6 +10,7 @@ The database API offers a convenient and efficient way to create MySQL and Postg
710
Follow these steps to have a local running copy of the app.
811

912
Clone The Repo
13+
1014
```
1115
git clone https://github.com/crane-cloud/database-api.git
1216
```
@@ -20,3 +24,5 @@ In the project directory, running `make` shows you a list of commands to use.
2024
Run `make start` to start the application and required services.
2125

2226
Run `make connect-to-container` to connect to the FastAPI application container.
27+
28+
Run `make test` to run tests in the application

0 commit comments

Comments
 (0)