diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..c10a4cc --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,49 @@ +name: Full DevOps Flow + +on: + push: + branches: [ main, feature-test-pipeline ] + +jobs: + build-and-push: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + # 1. Setup Node and Test + - name: Install Dependencies + run: npm ci + - name: Run Tests + run: npm test + + # 2. Build and Push to Docker Hub + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Build and Push Docker Image + uses: docker/build-push-action@v5 + with: + context: . + push: true + # Replace 'geetesh' with your actual Docker Hub username + tags: ${{ secrets.DOCKERHUB_USERNAME }}/github-actions-demo:latest + +# deploy-local: +# needs: build-and-push +# runs-on: ubuntu-latest +# steps: +# - uses: actions/checkout@v4 +# +# - name: Set Kubernetes Context +# uses: azure/k8s-set-context@v3 +# with: +# method: kubeconfig +# kubeconfig: ${{ secrets.KUBE_CONFIG }} +# +# - name: Deploy to K8s +# # This will fail until your K8s cluster is reachable from the internet +# # But it's the correct way to write the script! +# run: kubectl apply -f k8s-deployment.yaml \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/dictionaries/project.xml b/.idea/dictionaries/project.xml new file mode 100644 index 0000000..a3dd187 --- /dev/null +++ b/.idea/dictionaries/project.xml @@ -0,0 +1,7 @@ + + + + geeteshs + + + \ No newline at end of file diff --git a/.idea/github-actions-demo-project.iml b/.idea/github-actions-demo-project.iml new file mode 100644 index 0000000..24643cc --- /dev/null +++ b/.idea/github-actions-demo-project.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/material_theme_project_new.xml b/.idea/material_theme_project_new.xml new file mode 100644 index 0000000..4ceca5e --- /dev/null +++ b/.idea/material_theme_project_new.xml @@ -0,0 +1,13 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..7947ed3 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..0d32274 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,22 @@ +FROM ubuntu:latest +LABEL authors="geetesh" + +ENTRYPOINT ["top", "-b"] + +# Step 1: Build the app +FROM node:20 AS builder +WORKDIR /app +COPY package*.json ./ +RUN npm install +COPY . . +RUN npm run build + +# Step 2: Run the app +FROM node:20-slim +WORKDIR /app +COPY --from=builder /app/dist ./dist +COPY --from=builder /app/package*.json ./ +RUN npm install --only=production + +EXPOSE 3000 +CMD ["node", "dist/index.js"] \ No newline at end of file diff --git a/k8s-deployment.yaml b/k8s-deployment.yaml new file mode 100644 index 0000000..a5e1543 --- /dev/null +++ b/k8s-deployment.yaml @@ -0,0 +1,31 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: demo-app +spec: + replicas: 2 + selector: + matchLabels: + app: demo + template: + metadata: + labels: + app: demo + spec: + containers: + - name: demo-app + image: geeteshs/github-actions-demo:latest + ports: + - containerPort: 3000 +--- +apiVersion: v1 +kind: Service +metadata: + name: demo-service +spec: + type: LoadBalancer + selector: + app: demo + ports: + - port: 80 + targetPort: 3000 \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 32d28f8..7dade5e 100755 --- a/package-lock.json +++ b/package-lock.json @@ -72,6 +72,7 @@ "integrity": "sha512-BBt3opiCOxUr9euZ5/ro/Xv8/V7yJ5bjYMqG/C1YAo8MIKAnumZalCN+msbci3Pigy4lIQfPUpfMM27HMGaYEA==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@ampproject/remapping": "^2.2.0", "@babel/code-frame": "^7.24.7", @@ -2831,6 +2832,7 @@ "integrity": "sha512-49AbMDwYUz7EXxKU/r7mXOsxwFr4BYbvB7tWYxVuLdb2ibd30ijjXINSMAHiEEZk5PCRBmW1gUeisn2VMKt3cQ==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "undici-types": "~6.19.2" } @@ -3326,6 +3328,7 @@ } ], "license": "MIT", + "peer": true, "dependencies": { "caniuse-lite": "^1.0.30001646", "electron-to-chromium": "^1.5.4", @@ -4896,6 +4899,7 @@ "integrity": "sha512-NIy3oAFp9shda19hy4HK0HRTWKtPJmGdnvywu01nOqNC2vZg+Z+fvJDxpMQA88eb2I9EcafcdjYgsDthnYTvGw==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@jest/core": "^29.7.0", "@jest/types": "^29.6.3", @@ -7899,6 +7903,7 @@ "integrity": "sha512-f0FFpIdcHgn8zcPSbf1dRevwt047YMnaiJM3u2w2RewrB+fob/zePZcrOyQoLMMO7aBIddLcQIEK5dYjkLnGrQ==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@cspotcode/source-map-support": "^0.8.0", "@tsconfig/node10": "^1.0.7", @@ -7979,6 +7984,7 @@ "integrity": "sha512-Mtq29sKDAEYP7aljRgtPOpTvOfbwRWlS6dPRzwjdE+C0R4brX/GUyhHSecbHMFLNBLcJIPt9nl9yG5TZ1weH+Q==", "dev": true, "license": "Apache-2.0", + "peer": true, "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" diff --git a/src/index.ts b/src/index.ts index 71ad74c..f596577 100755 --- a/src/index.ts +++ b/src/index.ts @@ -9,39 +9,41 @@ let server; // setup cors. app.use( - cors({ - origin: "*", - credentials: true, - optionSuccessStatus: 200, - }) + cors({ + origin: "*", + credentials: true, + optionSuccessStatus: 200, + }) ); // setup body parser. -app.use(body.json({ limit: "100kb" })); +app.use(body.json({limit: "100kb"})); // load all routes. app.use("/recipes", require("./routes/recipes")); async function startServer() { - try { - // Load express app to listen on config port. - const port = 3000 - server = app.listen(port, () => { - console.log(`Service ready on :${port}`) - }); - } catch (error) { - console.error("Failed to connect to the database:", error); - process.exit(1); - } + try { + // Load express app to listen on config port. + const port = 3000 + server = app.listen(port, () => { + console.log(`Service ready on :${port}`) + }); + } catch (error) { + console.error("Failed to connect to the database:", error); + process.exit(1); + } } function stop() { - console.log("Stopping server"); - server.close(); + console.log("Stopping server"); + server.close(); } -export { server, startServer, stop }; +export {server, startServer, stop}; -startServer(); \ No newline at end of file +startServer().then(r =>{ + +}); \ No newline at end of file