Skip to content

Commit 7c9430e

Browse files
authored
Merge pull request #26 from crane-cloud/ch-add-releases-workflow
chore: add production release workflows
2 parents 8786dfa + 096e549 commit 7c9430e

20 files changed

+260
-369
lines changed

.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

+25-7
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ jobs:
4949
cache-from: type=gha
5050
cache-to: type=gha,mode=max
5151
context: .
52-
file: Dockerfile.api
52+
file: Dockerfile
5353
labels: ${{ steps.meta.outputs.labels }}
5454
push: true
5555
tags: ${{ steps.meta.outputs.tags }}
@@ -73,25 +73,43 @@ jobs:
7373
name: Deploy (Staging)
7474

7575
needs:
76-
- Build
76+
- build
7777

7878
runs-on: ubuntu-latest
7979
env:
80-
namespace: cranecloud-microservice
80+
namespace: cranecloud
8181
image: cranecloud/database-api
8282

8383
steps:
8484
- name: Checkout code
85-
uses: actions/checkout@v2
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 }}
8691

87-
- uses: azure/k8s-set-context@v1
92+
- name: Install (Gcloud)
93+
uses: google-github-actions/setup-gcloud@v2
8894
with:
89-
kubeconfig: ${{ secrets.RENU_KUBECONFIG}}
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/
90108
91109
- name: Helm Release
92110
run: |
93111
helm upgrade --install \
94-
database-api ./helm/chart \
112+
database-api cranecloud/cranecloud \
95113
--values helm/values.staging.yaml \
96114
--namespace $namespace \
97115
--set image.tag="${{ needs.build.outputs.tag }}" \

Dockerfile

+5-7
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

2421
#Exposing port for celery flower
25-
EXPOSE 5555
22+
# EXPOSE 5555
23+
ENTRYPOINT ["sh", "/app/scripts/start.sh"]

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Database API
2-
32
[![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)
45

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

celerybeat-schedule.dat

0 Bytes
Binary file not shown.

docker-compose.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ services:
1010
restart: always
1111
build:
1212
context: .
13-
dockerfile: Dockerfile.api
13+
dockerfile: Dockerfile
1414
container_name: database-api
1515
environment:
1616
PYTHONDONTWRITEBYTECODE: 1

Dockerfile.api renamed to docker/prod/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-
ENTRYPOINT ["sh", "/app/scripts/start.sh"]
25-
21+
#Exposing port for celery flower
22+
# EXPOSE 5555
23+
ENTRYPOINT ["sh", "/app/scripts/start-prod.sh"]

helm/chart/.helmignore

-23
This file was deleted.

helm/chart/Chart.yaml

-23
This file was deleted.

helm/chart/templates/_helpers.tpl

-47
This file was deleted.

0 commit comments

Comments
 (0)