Skip to content

Commit 6ba164e

Browse files
build: create app infra and ci components (#2)
* build: security file ignore * build: manifests for app * build: cicd pipeline for app --------- Co-authored-by: rustam.sharipov <keoroot@gmail.com>
1 parent 62b0a4a commit 6ba164e

4 files changed

Lines changed: 214 additions & 0 deletions

File tree

.github/workflows/deployment.yaml

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
name: Deployment
2+
3+
on:
4+
push:
5+
branches:
6+
- nodejs
7+
- dev
8+
release:
9+
types:
10+
- published
11+
12+
jobs:
13+
prepare:
14+
name: Prepare
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v3
19+
20+
- name: Read Version
21+
id: version
22+
run: |
23+
echo "Reading package.json"
24+
PACKAGE_VERSION=0.0.1
25+
## ./package.json
26+
echo "value=$PACKAGE_VERSION-build.${{ github.run_id }}" >> $GITHUB_OUTPUT
27+
28+
- name: Check Version
29+
run: |
30+
VERSION="${{ steps.version.outputs.value }}"
31+
if [[ "$VERSION" =~ ^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-((0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*)(\.(0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*))*))?(\+([0-9a-zA-Z-]+(\.[0-9a-zA-Z-]+)*))?$ ]]; then
32+
echo "Version: $VERSION"
33+
else
34+
echo "Invalid Version: $VERSION"
35+
exit 1
36+
fi
37+
38+
- name: Select Environment
39+
id: environment
40+
run: |
41+
COMMIT_MSG="$(git log -1 --pretty=%B)"
42+
echo "Commit: $COMMIT_MSG"
43+
if [[ "${{ github.event_name }}" == "push" ]]; then
44+
if [[ "${{ github.ref_name }}" == 'nodejs' ]]; then
45+
echo "value=stage" >> $GITHUB_OUTPUT
46+
elif [[ "${{ github.ref_name }}" == 'dev' ]]; then
47+
echo "value=dev" >> $GITHUB_OUTPUT
48+
fi
49+
if [[ "$COMMIT_MSG" == *_ci* ]]; then
50+
echo "condition=ci" >> $GITHUB_OUTPUT
51+
else
52+
echo "condition=all" >> $GITHUB_OUTPUT
53+
fi
54+
elif [[ "${{ github.event_name }}" == "release" && "${{ github.event.release.target_commitish }}" == 'main' ]]; then
55+
echo "value=prod" >> $GITHUB_OUTPUT
56+
fi
57+
58+
- name: Check Environment
59+
run: |
60+
ENV="${{ steps.environment.outputs.value }}"
61+
if [[ "$ENV" != "stage" && "$ENV" != "prod" && "$ENV" != "dev" ]]; then
62+
echo "Invalid Environment: $ENV"
63+
exit 1
64+
fi
65+
echo "Environment: $ENV"
66+
echo "Condition: ${{ steps.environment.outputs.condition }}"
67+
68+
outputs:
69+
version: ${{ steps.version.outputs.value }}
70+
environment: ${{ steps.environment.outputs.value }}
71+
condition: ${{ steps.environment.outputs.condition }}
72+
73+
build:
74+
name: Build
75+
runs-on: ubuntu-latest
76+
if: needs.prepare.outputs.condition != 'ci'
77+
needs: [prepare]
78+
steps:
79+
- name: Checkout code
80+
uses: actions/checkout@v3
81+
82+
- name: Set up Buildx
83+
uses: docker/setup-buildx-action@v1
84+
85+
- name: Login to Amazon ECR
86+
id: login-ecr
87+
uses: aws-actions/amazon-ecr-login@v1
88+
env:
89+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
90+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
91+
AWS_REGION: ${{ secrets.AWS_REGION }}
92+
93+
- name: Set repository info
94+
run: |
95+
echo "REPO=${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com" >> $GITHUB_ENV
96+
echo $value
97+
98+
- name: Build and push Document Parcer image to ECR
99+
uses: docker/build-push-action@v2
100+
if: needs.prepare.outputs.environment == 'stage' || needs.prepare.outputs.environment == 'dev' ## || (needs.prepare.outputs.environment == 'prod'
101+
with:
102+
context: .
103+
tags: ${{ env.REPO }}/document-parcer:${{ needs.prepare.outputs.version }}, ${{ env.REPO }}/document-parcer:${{ needs.prepare.outputs.environment }}-latest
104+
push: true
105+
106+
rollout:
107+
name: Rollout
108+
if: needs.prepare.outputs.condition != 'ci'
109+
needs: [prepare, build]
110+
runs-on: ubuntu-latest
111+
steps:
112+
- name: Checkout code
113+
uses: actions/checkout@v3
114+
115+
- name: Configure AWS credentials
116+
uses: aws-actions/configure-aws-credentials@v4
117+
with:
118+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
119+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
120+
aws-region: ${{ secrets.AWS_REGION }}
121+
122+
- name: Login to Amazon EKS for stage cluster
123+
run: |
124+
aws eks update-kubeconfig --name ${{ secrets.EKS_CLUSTER_NAME }} --region ${{ secrets.AWS_REGION }}
125+
126+
- name: Apply new workflow configurations for Document Parcer
127+
run: |
128+
kubectl apply -f .infra/${{ needs.prepare.outputs.environment }}/apps/document-parcer.yaml
129+
130+
- name: Rollout Document Parcer Deployment
131+
run: |
132+
kubectl rollout restart deploy document-parcer -n ${{ needs.prepare.outputs.environment }}
133+
kubectl rollout status deploy document-parcer -n ${{ needs.prepare.outputs.environment }} --timeout=300s

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/.infra/stage/security
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: document-parcer
5+
namespace: stage
6+
labels:
7+
app: document-parcer
8+
spec:
9+
replicas: 1 # Number of replicas of the application
10+
selector:
11+
matchLabels:
12+
app: document-parcer
13+
strategy:
14+
type: Recreate
15+
template:
16+
metadata:
17+
labels:
18+
app: document-parcer
19+
spec:
20+
volumes:
21+
- name: hoa-data
22+
persistentVolumeClaim:
23+
claimName: hoa-pvc
24+
containers:
25+
- name: document-parcer
26+
image: 533267116071.dkr.ecr.eu-central-1.amazonaws.com/document-parcer:stage-latest # The image to be used
27+
imagePullPolicy: Always
28+
command: ["/bin/sh", "-c"]
29+
args:
30+
- |
31+
uvicorn main:app --host 0.0.0.0 --port 8000
32+
# echo "--------Start migrate-----"
33+
# sleep 1200
34+
# echo "--------Finish seeding-----"
35+
ports:
36+
- containerPort: 5004 # App works on this port
37+
resources:
38+
requests:
39+
memory: "256Mi"
40+
cpu: "256m"
41+
limits:
42+
memory: "1280Mi"
43+
cpu: "1000m"
44+
45+
envFrom:
46+
- configMapRef:
47+
name: main-configs-document-parcer-01
48+
- secretRef:
49+
name: main-creds-document-parcer-02
50+
volumeMounts:
51+
- mountPath: "/app/cache"
52+
name: hoa-data
53+
---
54+
apiVersion: v1
55+
kind: Service
56+
metadata:
57+
name: document-parcer-svc
58+
namespace: stage
59+
annotations:
60+
alb.ingress.kubernetes.io/healthcheck-path: /health
61+
alb.ingress.kubernetes.io/healthcheck-interval-seconds: "300"
62+
alb.ingress.kubernetes.io/healthcheck-timeout-seconds: "5"
63+
alb.ingress.kubernetes.io/healthy-threshold-count: "3"
64+
alb.ingress.kubernetes.io/unhealthy-threshold-count: "3"
65+
spec:
66+
type: ClusterIP
67+
selector:
68+
app: document-parcer
69+
ports:
70+
- port: 5004
71+
targetPort: 5004
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
name: main-configs-document-parcer-01
5+
namespace: stage
6+
data:
7+
BASE_URL: "http://document-parcer.svc.cluster.local"
8+
LM_STUDIO_URL: "https://chat-stg.zentegrio.com"
9+
DOCUMENT_CONVERTER_URL: "http://document-parcer.svc.cluster.local:5004/convert"

0 commit comments

Comments
 (0)