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

feat: incluindo o Dockerfile e Manifesto para fazer o deploy usando K… #37

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
41 changes: 41 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
pipeline {
agent any

stages {

stage ('Build Docker Image') {
steps {
script {
dockerapp = docker.build("ilaraca/kube-news:${env.BUILD_ID}", '-f ./src/Dockerfile ./src')
}
}
}

stage ('Push Docker Image') {
steps {
script {
docker.withRegistry('https://registry.hub.docker.com', 'dockerhub') {
dockerapp.push('latest')
dockerapp.push("${env.BUILD_ID}")
}
}
}
}

stage ('Deploy Kubernetes') {

environment {
tag_version = "${env.BUILD_ID}"
}
steps {
withKubeConfig ([credentialsId: 'kubeconfig']) {


sh 'sed -i "s/{{TAG}}/$tag_version/g" ./k8s/deployment.yaml'
sh 'kubectl apply -f ./k8s/deployment.yaml'

}
}
}
}
}
87 changes: 87 additions & 0 deletions k8s/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: postgre
spec:
selector:
matchLabels:
app: postgre
template:
metadata:
labels:
app: postgre
spec:
containers:
- name: postgre
image: postgres:15.0
ports:
- containerPort: 5432
env:
- name: POSTGRES_DB
value: "kubenews"
- name: POSTGRES_USER
value: "kubenews"
- name: POSTGRES_PASSWORD
value: "Pg#123"

---

apiVersion: v1
kind: Service
metadata:
name: postgre
spec:
selector:
app: postgre
ports:
- port: 5432
type: ClusterIP

---

apiVersion: apps/v1
kind: Deployment
metadata:
name: web
spec:
selector:
matchLabels:
app: web
template:
metadata:
labels:
app: web
annotations:
prometheus.io/scrape: "true"
prometheus.io/port: "8080"
prometheus.io/path: "/metrics"
spec:
containers:
- name: web
image: ilaraca/kube-news:{{TAG}}
ports:
- containerPort: 8080
env:
- name: DB_DATABASE
value: "kubenews"
- name: DB_USERNAME
value: "kubenews"
- name: DB_PASSWORD
value: "Pg#123"
- name: DB_HOST
value: "postgre"

---

apiVersion: v1
kind: Service
metadata:
name: web
spec:
selector:
app: web
ports:
- port: 80
# faz o redirecionamento da porta 8080
targetPort: 8080
type: LoadBalancer
7 changes: 7 additions & 0 deletions src/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM node:18.11.0
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 8080
CMD ["node", "server.js"]
2 changes: 1 addition & 1 deletion src/views/partial/nav-bar.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<div class="container-fluid">
<a class="navbar-brand text-warning" href="/">KubeNews</a>
<a class="navbar-brand text-warning" href="/">KubeNews-v3</a>
<ul class="nav">
<li class="nav-item">
<a class="nav-link active" style="color: #ffc105;" aria-current="page" href="/post">Novo Post</a>
Expand Down