Skip to content

Commit

Permalink
Commit Inicial
Browse files Browse the repository at this point in the history
  • Loading branch information
fabricioveronez committed Jun 3, 2024
1 parent ade08f4 commit e1c88cc
Show file tree
Hide file tree
Showing 7 changed files with 807 additions and 0 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1 +1,52 @@

name: CI-CD

on:
workflow_dispatch:
push:
env:
docker_image: fabricioveronez/nodejs-web

jobs:
CI:
runs-on: ubuntu-latest
steps:
- name: Obtendo o código
uses: actions/checkout@v4
- name: Docker Login
uses: docker/login-action@v3
with:
username: ${{secrets.DOCKERHUB_USER}}
password: ${{secrets.DOCKERHUB_PWD}}

- name: Construção da imagem Docker worker
uses: docker/build-push-action@v5
with:
context: ./src
file: ./src/Dockerfile
push: true
tags: |
"${{ env.docker_image }}:${{github.run_number}}"
"${{ env.docker_image }}:latest"
CD:
runs-on: ubuntu-latest
needs: [CI]

steps:
- name: Obtendo o código
uses: actions/checkout@v3

- name: Configuração do Kubeconfig
uses: azure/k8s-set-context@v4
with:
method: kubeconfig
kubeconfig: ${{ secrets.K8S_CONFIG }}

- name: Deploy no cluster Kubernetes
uses: Azure/k8s-deploy@v5
with:
manifests: |
./k8s/deployment.yaml
images: |
"${{ env.docker_image }}:${{github.run_number}}"
30 changes: 30 additions & 0 deletions k8s/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: web
spec:
selector:
matchLabels:
app: web
template:
metadata:
labels:
app: web
spec:
containers:
- name: web
image: fabricioveronez/nodejs-web
ports:
- containerPort: 8080
---
apiVersion: v1
kind: Service
metadata:
name: web
spec:
selector:
app: web
ports:
- port: 80
targetPort: 8080
type: LoadBalancer
1 change: 1 addition & 0 deletions src/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
7 changes: 7 additions & 0 deletions src/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM node:20.12.0
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 8080
CMD ["node", "index.js"]
10 changes: 10 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const express = require('express');
const app = express();

app.route('/').get((req, res) => {
res.send('<h1>Aplicacao exemplo</h1>');
});

app.listen(8080, () => {
console.log('Aplicacao rodando na porta 3000');
});
Loading

0 comments on commit e1c88cc

Please sign in to comment.