Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: deploy to GCP #13

Merged
merged 12 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
130 changes: 130 additions & 0 deletions .github/workflows/prod.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
---
name: Prod

on:
release:
types:
- released
- prereleased

jobs:
build:
outputs:
image: ${{ steps.export.outputs.image }}
tag: ${{ steps.export.outputs.tag }}

runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: main # Reference branch

- name: Install (Buildx)
uses: docker/setup-buildx-action@v3

- name: Login (GCP)
uses: google-github-actions/auth@v2
with:
credentials_json: ${{ secrets.CREDENTIALS_JSON }}

- name: Install (Gcloud)
uses: google-github-actions/setup-gcloud@v1
with:
project_id: crane-cloud-274413
install_components: "gke-gcloud-auth-plugin"

- name: Login (GCR)
run: gcloud auth configure-docker

- id: meta
name: Tag
uses: docker/metadata-action@v3
with:
flavor: |
latest=true
images: gcr.io/crane-cloud-274413/activity-logger
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=sha

- name: Build
uses: docker/build-push-action@v2
with:
cache-from: type=gha
cache-to: type=gha,mode=max
context: .
file: Dockerfile
labels: ${{ steps.meta.outputs.labels }}
push: true
tags: ${{ steps.meta.outputs.tags }}

- id: export
name: Export
uses: actions/github-script@v5
with:
script: |
const metadata = JSON.parse(`${{ steps.meta.outputs.json }}`)
const fullUrl = metadata.tags.find((t) => t.includes(':sha-'))
if (fullUrl == null) {
core.error('Unable to find sha tag of image')
} else {
const tag = fullUrl.split(':')[1]
core.setOutput('image', fullUrl)
core.setOutput('tag', tag)
}

Production:
name: Deploy (Production)

needs:
- build

runs-on: ubuntu-latest

env:
namespace: cranecloud-prod

steps:
- name: Clone
uses: actions/checkout@v2

- name: Login (GCP)
uses: google-github-actions/auth@v2
with:
credentials_json: ${{ secrets.CREDENTIALS_JSON }}

- name: Install (Gcloud)
uses: google-github-actions/setup-gcloud@v1
with:
project_id: crane-cloud-274413
install_components: "gke-gcloud-auth-plugin"

- name: Login (Kubernetes Cluster)
uses: google-github-actions/get-gke-credentials@v1
with:
cluster_name: staging-cluster
location: us-central1-a
project_id: crane-cloud-274413

- name: Add Repo (cranecloud)
run: |
helm repo add cranecloud https://crane-cloud.github.io/helm-charts/

- name: Helm Release
run: |
helm upgrade --install \
activity-logger cranecloud/cranecloud \
--values helm/values.prod.yaml \
--namespace $namespace \
--set image.tag="${{ needs.build.outputs.tag }}" \
--set environment.JWT_SALT="${{ secrets.PRODUCTION_JWT_SALT }}" \
--timeout=300s

- name: Monitor Rollout
run: |
kubectl rollout status deployment/activity-logger --timeout=300s --namespace $namespace
41 changes: 27 additions & 14 deletions .github/workflows/staging.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ on:
push:
branches:
- develop
- ft-add-mongo-deployment

workflow_dispatch:

Expand All @@ -21,10 +20,10 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Install (Buildx)
uses: docker/setup-buildx-action@v1
uses: docker/setup-buildx-action@v3

- name: Login to Docker Hub
uses: docker/login-action@v2
Expand All @@ -45,7 +44,7 @@ jobs:
type=sha

- name: Build
uses: docker/build-push-action@v2
uses: docker/build-push-action@v5
with:
cache-from: type=gha
cache-to: type=gha,mode=max
Expand All @@ -56,7 +55,7 @@ jobs:

- id: export
name: Export
uses: actions/github-script@v5
uses: actions/github-script@v7
with:
script: |
const metadata = JSON.parse(`${{ steps.meta.outputs.json }}`)
Expand All @@ -73,29 +72,43 @@ jobs:
name: Deploy (Staging)

needs:
- Build
- build

runs-on: ubuntu-latest
env:
namespace: cranecloud-microservice
namespace: cranecloud
image: cranecloud/activity-logger

steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4

- uses: azure/k8s-set-context@v1
- name: Login (GCP)
uses: google-github-actions/auth@v2
with:
kubeconfig: ${{ secrets.RENU_KUBECONFIG}}
credentials_json: ${{ secrets.CREDENTIALS_JSON }}

# - name: Add Repo (cranecloud-backend)
# run: |
# helm repo add cranecloud-backend https://crane-cloud.github.io/helm-charts/
- name: Install (Gcloud)
uses: google-github-actions/setup-gcloud@v2
with:
project_id: crane-cloud-274413
install_components: "gke-gcloud-auth-plugin"

- name: Login (Kubernetes Cluster)
uses: google-github-actions/get-gke-credentials@v2
with:
cluster_name: staging-cluster
location: us-central1-a
project_id: crane-cloud-274413

- name: Add Repo (cranecloud)
run: |
helm repo add cranecloud https://crane-cloud.github.io/helm-charts/

- name: Helm Release
run: |
helm upgrade --install \
activity-logger ./helm/chart \
activity-logger cranecloud/cranecloud \
--values helm/values.staging.yaml \
--namespace $namespace \
--set image.tag="${{ needs.build.outputs.tag }}" \
Expand Down
8 changes: 3 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,16 @@ ENV DEBIAN_FRONTEND='noninteractive'

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

COPY ./README.md /app/README.md

RUN pip install poetry

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

COPY ./pyproject.toml /app/pyproject.toml

COPY ./poetry.lock /app/poetry.lock

COPY . /app

RUN poetry install

COPY . /app

#for celery to have a different working directory
COPY . /celery-app
Expand Down
23 changes: 0 additions & 23 deletions helm/chart/.helmignore

This file was deleted.

23 changes: 0 additions & 23 deletions helm/chart/Chart.yaml

This file was deleted.

47 changes: 0 additions & 47 deletions helm/chart/templates/_helpers.tpl

This file was deleted.

54 changes: 0 additions & 54 deletions helm/chart/templates/celery-deployment.yaml

This file was deleted.

Loading