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

Feature/deploy new version #14

Merged
merged 42 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
1e95f5f
Updated backend settings in order to prepare for deployment
dopic Oct 21, 2024
948a04b
Merge branch 'main' into feature/deploy-new-version
dopic Oct 21, 2024
10d867c
Merge branch 'main' into feature/deploy-new-version
dopic Oct 21, 2024
39e3262
Update frontend deployment config
dopic Oct 21, 2024
aeff8f9
Add chart
dopic Oct 22, 2024
1271c61
Test
dopic Oct 22, 2024
eb03ebf
Fix
dopic Oct 22, 2024
c5a5e65
Update deployment config
dopic Oct 22, 2024
93f7bb9
Add frontend deploy
dopic Oct 22, 2024
145b696
Fix ingress path
dopic Oct 22, 2024
b9116ae
Add wait to helm deploy in pipeline
dopic Oct 22, 2024
1ea9c9b
fix auth
dopic Oct 22, 2024
190230f
fix route
dopic Oct 22, 2024
f8e2e8b
fix route
dopic Oct 22, 2024
a4a3f63
Fix backenduri
dopic Oct 22, 2024
a911974
Added Sharp lib to frontend
dopic Oct 22, 2024
ced9373
Update Graphql uri
dopic Oct 22, 2024
dd7c6da
Change Graphql URI
dopic Oct 22, 2024
f8dd5cb
Add token to request
dopic Oct 23, 2024
7d28d8e
Update access-token
dopic Oct 23, 2024
326bbb0
Test
dopic Oct 23, 2024
76b00db
Updates
dopic Oct 23, 2024
3fa8eef
Test
dopic Oct 23, 2024
0382fc5
Test
dopic Oct 23, 2024
6f4f910
Test
dopic Oct 23, 2024
81695bf
Test
dopic Oct 23, 2024
87e67fb
Test
dopic Oct 23, 2024
c53646f
Test
dopic Oct 23, 2024
2943da8
Test
dopic Oct 23, 2024
8ff6533
Test
dopic Oct 23, 2024
e466c23
Test
dopic Oct 23, 2024
401ed2c
EnableAPI
dopic Oct 23, 2024
0727b0e
Updates
dopic Oct 23, 2024
bcc4a0c
Add logs
dopic Oct 23, 2024
8b22639
Update auth
dopic Oct 23, 2024
98684d9
Merge branch 'main' into feature/deploy-new-version
dopic Oct 23, 2024
8ecaa5c
Update yarn lockfile
dopic Oct 23, 2024
a2af41e
Fixes
dopic Oct 23, 2024
bb63069
Minor Fixes
dopic Oct 23, 2024
694fad4
Add messages
dopic Oct 23, 2024
0dd5597
Fix server host
dopic Oct 23, 2024
0724226
Merge branch 'main' into feature/deploy-new-version
dopic Oct 24, 2024
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
38 changes: 19 additions & 19 deletions .github/workflows/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: Docker Image CI

on:
push:
branches: [ "main" ]
branches: [ "feature/deploy-new-version" ]
pull_request:
branches: [ "main" ]
branches: [ "feature/deploy-new-version" ]

permissions:
id-token: write # This is required for requesting the JWT
Expand All @@ -16,13 +16,16 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Build the Docker image
run: docker build . --tag 256696114092.dkr.ecr.us-east-1.amazonaws.com/omniscope/app:${{ github.run_id }} --tag 256696114092.dkr.ecr.us-east-1.amazonaws.com/omniscope/app:latest
- name: Build the Docker image - Frontend
run: docker build ./frontend --tag 339713015367.dkr.ecr.us-east-1.amazonaws.com/omniscope/frontend:${{ github.run_id }} --tag 339713015367.dkr.ecr.us-east-1.amazonaws.com/omniscope/frontend:latest

- name: Build the Docker image - Backend
run: docker build ./backend --tag 339713015367.dkr.ecr.us-east-1.amazonaws.com/omniscope/backend:${{ github.run_id }} --tag 339713015367.dkr.ecr.us-east-1.amazonaws.com/omniscope/backend:latest

- name: configure aws credentials
uses: aws-actions/configure-aws-credentials@v3
with:
role-to-assume: arn:aws:iam::256696114092:role/GithubDeploymentRole
role-to-assume: arn:aws:iam::339713015367:role/GithubIdentityProviderRole
role-session-name: GithubSession
aws-region: us-east-1

Expand All @@ -31,32 +34,29 @@ jobs:

- name: Push Docker images
run: |
docker image push 256696114092.dkr.ecr.us-east-1.amazonaws.com/omniscope/app:${{ github.run_id }}
docker image push 256696114092.dkr.ecr.us-east-1.amazonaws.com/omniscope/app:latest
docker image push 339713015367.dkr.ecr.us-east-1.amazonaws.com/omniscope/frontend:${{ github.run_id }}
docker image push 339713015367.dkr.ecr.us-east-1.amazonaws.com/omniscope/frontend:latest
docker image push 339713015367.dkr.ecr.us-east-1.amazonaws.com/omniscope/backend:${{ github.run_id }}
docker image push 339713015367.dkr.ecr.us-east-1.amazonaws.com/omniscope/backend:latest

deploy:
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v4
- name: configure aws credentials
uses: aws-actions/configure-aws-credentials@v3
with:
role-to-assume: arn:aws:iam::256696114092:role/GithubDeploymentRole
role-to-assume: arn:aws:iam::339713015367:role/GithubIdentityProviderRole
role-session-name: GithubSession
aws-region: us-east-1

#TODO: Atualizar a task definition e o service
- name: ECS Restart Service
run: aws ecs update-service --cluster arn:aws:ecs:us-east-1:256696114092:cluster/fargate-spot-stack-ecscluster7830E7B5-5A2jZtnQeSlV --service omniscope-app --region us-east-1 --force-new-deployment
- name: Deploy Backend
run: |
aws eks update-kubeconfig --name ia-factory-cluster --region us-east-1
helm upgrade --install backend ./deploy/chart/omniscope --namespace omniscope -f ./deploy/values-backend.yml --set image.tag=${{ github.run_id }} --wait
helm upgrade --install frontend ./deploy/chart/omniscope --namespace omniscope -f ./deploy/values-frontend.yml --set image.tag=${{ github.run_id }} --wait

# aws ecs update-service --cluster <nome_do_cluster> --service <nome_do_serviço> --force-new-deployment
# - name: ECS Restart Service
# uses: apideck-libraries/ecs-restart-service@v1
# with:
# service: ominiscope-app
# # The short name or full Amazon Resource Name (ARN) of the cluster that your service runs on. If you do not specify a cluster, the default cluster is assumed.
# cluster: arn:aws:ecs:us-east-1:256696114092:cluster/fargate-spot-stack-ecscluster7830E7B5-5A2jZtnQeSlV




Expand Down
16 changes: 0 additions & 16 deletions Dockerfile

This file was deleted.

15 changes: 15 additions & 0 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM python:3.12-slim

WORKDIR /code

COPY ./requirements.txt /code/requirements.txt

RUN pip install --no-cache-dir --upgrade -r ./requirements.txt

COPY . .

EXPOSE 80

CMD ["python", "src/app.py"]

RUN mkdir /.cache && chmod 777 /.cache
9 changes: 9 additions & 0 deletions backend/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
requests
Flask
Flask-CORS
flask_httpauth
ariadne

google-auth
Expand All @@ -8,3 +10,10 @@ pytest-cov
pytest-mock
pytest-parametrize


pydantic
pytz
python-dotenv
validators
pandas
jwt
8 changes: 4 additions & 4 deletions backend/src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
from api.mutations import mutation
import logging
import argparse

import sys
from api.execution_stats import ExecutionStatsExtension
import globals

def verify_token(token):
try:
# Use the client_id from your settings
idinfo = id_token.verify_oauth2_token(token, requests.Request(), auth_settings["client_id"])

print(idinfo, file=sys.stderr)
if idinfo['iss'] not in ['accounts.google.com', 'https://accounts.google.com']:
raise ValueError('Wrong issuer.')

Expand Down Expand Up @@ -54,7 +54,7 @@ def decorated(*args, **kwargs):
app = Flask(__name__)
CORS(app)

type_defs = load_schema_from_path("api/schema.graphql")
type_defs = load_schema_from_path("src/api/schema.graphql")
schema = make_executable_schema(
type_defs,
query,
Expand Down Expand Up @@ -97,5 +97,5 @@ def graphql_server():

app.logger.info("Starting the application")
globals.update()
app.run(debug=args.verbose)
app.run(debug=args.verbose,host="0.0.0.0")

14 changes: 14 additions & 0 deletions deploy/cert/issuer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: cert-manager.io/v1
kind: Issuer
metadata:
name: letsencrypt
spec:
acme:
email: [email protected]
privateKeySecretRef:
name: letsencrypt-private-key
server: https://acme-v02.api.letsencrypt.org/directory
solvers:
- http01:
ingress:
ingressClassName: nginx
23 changes: 23 additions & 0 deletions deploy/chart/omniscope/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
24 changes: 24 additions & 0 deletions deploy/chart/omniscope/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: v2
name: omniscope
description: A Helm chart for Kubernetes

# A chart can be either an 'application' or a 'library' chart.
#
# Application charts are a collection of templates that can be packaged into versioned archives
# to be deployed.
#
# Library charts provide useful utilities or functions for the chart developer. They're included as
# a dependency of application charts to inject those utilities and functions into the rendering
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
type: application

# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.1.0

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "1.16.0"
62 changes: 62 additions & 0 deletions deploy/chart/omniscope/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "omniscope.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "omniscope.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Chart.Name .Values.nameOverride }}
{{- if contains $name .Release.Name }}
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}
{{- end }}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "omniscope.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "omniscope.labels" -}}
helm.sh/chart: {{ include "omniscope.chart" . }}
{{ include "omniscope.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "omniscope.selectorLabels" -}}
app.kubernetes.io/name: {{ include "omniscope.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{/*
Create the name of the service account to use
*/}}
{{- define "omniscope.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "omniscope.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
40 changes: 40 additions & 0 deletions deploy/chart/omniscope/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "omniscope.fullname" . }}
labels:
{{- include "omniscope.labels" . | nindent 4 }}
spec:
replicas: {{ .Values.replicaCount }}
selector:
matchLabels:
{{- include "omniscope.selectorLabels" . | nindent 6 }}
template:
metadata:
{{- with .Values.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "omniscope.labels" . | nindent 8 }}
{{- with .Values.podLabels }}
{{- toYaml . | nindent 8 }}
{{- end }}
spec:
containers:
- name: {{ .Chart.Name }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
- name: http
containerPort: {{ .Values.service.port }}
protocol: TCP
env:
{{- toYaml .Values.envVars | nindent 12 }}

livenessProbe:
{{- toYaml .Values.livenessProbe | nindent 12 }}
readinessProbe:
{{- toYaml .Values.readinessProbe | nindent 12 }}
resources:
{{- toYaml .Values.resources | nindent 12 }}
41 changes: 41 additions & 0 deletions deploy/chart/omniscope/templates/ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{{- if .Values.ingress.enabled -}}
{{- $fullName := include "omniscope.fullname" . -}}
{{- $svcPort := .Values.service.port -}}
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: {{ $fullName }}
labels:
{{- include "omniscope.labels" . | nindent 4 }}
{{- with .Values.ingress.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
ingressClassName: {{ .Values.ingress.className }}
{{- if .Values.ingress.tls }}
tls:
{{- range .Values.ingress.tls }}
- hosts:
{{- range .hosts }}
- {{ . | quote }}
{{- end }}
secretName: {{ .secretName }}
{{- end }}
{{- end }}
rules:
{{- range .Values.ingress.hosts }}
- host: {{ .host | quote }}
http:
paths:
{{- range .paths }}
- path: {{ .path }}
pathType: {{ .pathType }}
backend:
service:
name: {{ $fullName }}
port:
number: {{ $svcPort }}
{{- end }}
{{- end }}
{{- end }}
15 changes: 15 additions & 0 deletions deploy/chart/omniscope/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: v1
kind: Service
metadata:
name: {{ include "omniscope.fullname" . }}
labels:
{{- include "omniscope.labels" . | nindent 4 }}
spec:
type: {{ .Values.service.type }}
ports:
- port: {{ .Values.service.port }}
targetPort: http
protocol: TCP
name: http
selector:
{{- include "omniscope.selectorLabels" . | nindent 4 }}
Loading
Loading