Skip to content

Commit 1e7997a

Browse files
committed
add prod deployment
1 parent ebc7ecc commit 1e7997a

15 files changed

Lines changed: 212 additions & 387 deletions

.github/workflows/prod.yml

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

.github/workflows/staging.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ on:
55
push:
66
branches:
77
- master
8-
- deploy/gcp
98

109
workflow_dispatch:
1110

@@ -110,7 +109,6 @@ jobs:
110109
run: |
111110
helm repo add cranecloud https://crane-cloud.github.io/helm-charts/
112111
113-
# monitoring-api ./helm/chart \
114112
- name: Helm Release
115113
run: |
116114
helm upgrade --install --create-namespace \

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.

helm/chart/templates/celery-deployment.yaml

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

0 commit comments

Comments
 (0)