-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #298 from Mohmn/api-devops
feat: add k8s files and ci cd files for user api
- Loading branch information
Showing
14 changed files
with
259 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
name: CI for New Pull Requests | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- "*" | ||
paths: | ||
- 'apps/user/**' # Only trigger for changes in the apps/user directory | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Use Node.js 18.x | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: '18.x' | ||
|
||
- name: Install dependencies for specific package | ||
run: yarn workspace greenstand-wallet-app-api install | ||
|
||
- name: Build TypeScript project | ||
run: yarn workspace greenstand-wallet-app-api build | ||
|
||
- name: Lint code with ESLint | ||
run: yarn workspace greenstand-wallet-app-api lint | ||
|
||
- name: Run tests | ||
run: yarn workspace greenstand-wallet-app-api test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
name: Service CI/CD Pipeline to Release and Deploy to Dev Env | ||
|
||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
paths: | ||
- 'apps/user/**' # Only trigger for changes in the apps/user directory | ||
|
||
jobs: | ||
release: | ||
if: | | ||
!contains(github.event.head_commit.message, 'skip-ci') | ||
name: Build and Release Docker Image | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Use Node.js 20.x | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: '20.x' | ||
|
||
- name: Yarn Clean Install | ||
run: yarn workspace greenstand-wallet-app-api install | ||
|
||
- name: Install Semantic Release | ||
run: yarn global add semantic-release @semantic-release/{git,exec,changelog} | ||
|
||
- name: Semantic Release | ||
run: semantic-release | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Make Build | ||
run: yarn workspace greenstand-wallet-app-api build | ||
|
||
- name: Get NPM Version | ||
id: package-version | ||
uses: martinbeentjes/npm-get-version-action@master | ||
with: | ||
path: apps/user | ||
|
||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@v3 | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
|
||
- name: Login to DockerHub | ||
uses: docker/login-action@v3 | ||
with: | ||
username: ${{ secrets.DOCKERHUB_USERNAME }} | ||
password: ${{ secrets.DOCKERHUB_TOKEN }} | ||
|
||
|
||
- name: Build and Push Docker Image | ||
id: docker_build_release | ||
uses: docker/build-push-action@v5 | ||
with: | ||
context: ./apps/user/ | ||
file: ./apps/user/Dockerfile | ||
push: true | ||
tags: greenstand/treetracker-wallet-monorepo-user-api:${{ steps.package-version.outputs.current-version }} | ||
|
||
outputs: | ||
bumped_version: ${{ steps.package-version.outputs.current-version }} | ||
|
||
deploy: | ||
if: ${{ needs.release.result == 'success' }} && !contains(github.event.head_commit.message, 'skip-ci') | ||
name: Deploy to Dev Environment | ||
runs-on: ubuntu-latest | ||
needs: release | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Install Kustomize | ||
run: | | ||
curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash | ||
- name: Update Kustomize Image | ||
run: | | ||
(cd apps/user/deployment/base && kustomize edit set image greenstand/treetracker-wallet-monorepo-user-api:${{ needs.release.outputs.bumped_version }}) | ||
- name: Install DigitalOcean CLI | ||
uses: digitalocean/action-doctl@v2 | ||
with: | ||
token: ${{ secrets.DEV_DIGITALOCEAN_TOKEN }} | ||
|
||
- name: Save Kubernetes Config | ||
run: doctl kubernetes cluster kubeconfig save ${{ secrets.DEV_CLUSTER_NAME }} | ||
|
||
- name: Deploy to Kubernetes | ||
run: | | ||
kustomize build apps/user/deployment/overlays/development | \ | ||
kubectl apply -n ${{ secrets.K8S_NAMESPACE }} --wait -f - |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
deployment | ||
node_modules | ||
dist | ||
.git | ||
.cache | ||
.env | ||
.github | ||
.husky |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
FROM node:18-alpine AS builder | ||
WORKDIR /app | ||
ENV PATH=/app/node_modules/.bin:$PATH | ||
COPY package.json ./ | ||
RUN yarn install --silent | ||
COPY . . | ||
RUN yarn build | ||
RUN yarn install --production --ignore-scripts --prefer-offline | ||
FROM node:18-alpine AS prod | ||
WORKDIR /app | ||
COPY --from=builder app/dist/ ./dist | ||
COPY --from=builder app/node_modules ./node_modules | ||
EXPOSE 8080 | ||
CMD ["node", "dist/src/main.js"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRoleBinding | ||
metadata: | ||
name: k8s-wait-for | ||
# annotations: | ||
subjects: | ||
- kind: ServiceAccount | ||
name: default | ||
namespace: treetracker-wallet-monorepo-user-api | ||
roleRef: | ||
kind: ClusterRole | ||
name: k8s-wait-for | ||
apiGroup: rbac.authorization.k8s.io |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRole | ||
metadata: | ||
name: k8s-wait-for | ||
# annotations: | ||
rules: | ||
- apiGroups: [''] | ||
resources: ['services', 'pods', 'jobs'] | ||
verbs: ['get', 'watch', 'list'] | ||
- apiGroups: ['batch'] | ||
resources: ['services', 'pods', 'jobs'] | ||
verbs: ['get', 'watch', 'list'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: treetracker-wallet-monorepo-user-api | ||
labels: | ||
app: treetracker-wallet-monorepo-user-api | ||
namespace: treetracker-wallet-monorepo-user-api | ||
spec: | ||
replicas: 2 | ||
selector: | ||
matchLabels: | ||
app: treetracker-wallet-monorepo-user-api | ||
template: | ||
metadata: | ||
labels: | ||
app: treetracker-wallet-monorepo-user-api | ||
spec: | ||
affinity: | ||
nodeAffinity: | ||
requiredDuringSchedulingIgnoredDuringExecution: | ||
nodeSelectorTerms: | ||
- matchExpressions: | ||
- key: doks.digitalocean.com/node-pool | ||
operator: In | ||
values: | ||
- microservices-node-pool | ||
containers: | ||
- name: treetracker-wallet-monorepo-user-api | ||
image: greenstand/treetracker-wallet-monorepo-user-api:TAG | ||
# get this from env as well | ||
ports: | ||
- containerPort: 8080 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
resources: | ||
- deployment.yaml | ||
- mapping.yaml | ||
- service.yaml | ||
- namespace.yaml | ||
- cluster-role.yaml | ||
- cluster-role-binding.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
apiVersion: getambassador.io/v2 | ||
kind: Mapping | ||
metadata: | ||
name: treetracker-wallet-monorepo-user-api | ||
spec: | ||
prefix: /monorepo-user/ | ||
service: treetracker-wallet-monorepo-user-api-service |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
apiVersion: v1 | ||
kind: Namespace | ||
metadata: | ||
name: treetracker-wallet-monorepo-user-api |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: treetracker-wallet-monorepo-user-api-service | ||
namespace: treetracker-wallet-monorepo-user-api | ||
spec: | ||
selector: | ||
app: treetracker-wallet-monorepo-user-api | ||
ports: | ||
- protocol: TCP | ||
port: 80 | ||
targetPort: 8080 | ||
type: ClusterIP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
resources: | ||
- ../../base | ||
patchesStrategicMerge: | ||
- mapping.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
apiVersion: getambassador.io/v2 | ||
kind: Mapping | ||
metadata: | ||
name: treetracker-wallet-monorepo-user-api | ||
spec: | ||
cors: | ||
origins: "*" | ||
methods: GET, POST, PATCH, OPTIONS | ||
headers: | ||
- Content-Type | ||
- Authorization |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters