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

Circleci project setup #2

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Use the latest 2.1 version of CircleCI pipeline process engine.
# See: https://circleci.com/docs/2.0/configuration-reference
version: 2.1

# Define a job to be invoked later in a workflow.
# See: https://circleci.com/docs/2.0/configuration-reference/#jobs
jobs:
say-hello:
# Specify the execution environment. You can specify an image from Dockerhub or use one of our Convenience Images from CircleCI's Developer Hub.
# See: https://circleci.com/docs/2.0/configuration-reference/#docker-machine-macos-windows-executor
docker:
- image: cimg/base:stable
# Add steps to the job
# See: https://circleci.com/docs/2.0/configuration-reference/#steps
steps:
- checkout
- run:
name: "Say hello"
command: "echo Hello, World!"

# Invoke jobs via workflows
# See: https://circleci.com/docs/2.0/configuration-reference/#workflows
workflows:
say-hello-workflow:
jobs:
- say-hello
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ Dockerfile
.git
README.md
.gitignore
.env
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,6 @@ typings/

#DynamoDB Local files
.dynamodb/

# password
secret.yaml
4 changes: 2 additions & 2 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const db = require('./db');
const sharks = require('./routes/sharks');

const path = __dirname + '/views/';
const port = 8080;
const port = process.env.PORT || 8080;

app.engine('html', require('ejs').renderFile);
app.set('view engine', 'html');
Expand All @@ -14,5 +14,5 @@ app.use(express.static(path));
app.use('/sharks', sharks);

app.listen(port, function () {
console.log('Example app listening on port 8080!')
console.log('Example app listening on port ${port}!')
})
54 changes: 54 additions & 0 deletions db-deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
annotations:
kompose.cmd: kompose convert
kompose.version: 1.18.0 (06a2e56)
creationTimestamp: null
labels:
io.kompose.service: db
name: db
spec:
replicas: 1
strategy:
type: Recreate
template:
metadata:
creationTimestamp: null
labels:
io.kompose.service: db
spec:
containers:
- env:
- name: MONGO_DB
valueFrom:
configMapKeyRef:
key: MONGO_DB
name: db-env
- name: MONGO_INITDB_ROOT_PASSWORD
valueFrom:
secretKeyRef:
name: mongo-secret
key: MONGO_PASSWORD
- name: MONGO_INITDB_ROOT_USERNAME
valueFrom:
secretKeyRef:
name: mongo-secret
key: MONGO_USERNAME
- name: MONGO_PORT
valueFrom:
configMapKeyRef:
key: MONGO_PORT
name: db-env
image: mongo:4.1.8-xenial
name: db
resources: {}
volumeMounts:
- mountPath: /data/db
name: dbdata
restartPolicy: Always
volumes:
- name: dbdata
persistentVolumeClaim:
claimName: dbdata
status: {}
10 changes: 10 additions & 0 deletions db-env-configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: v1
data:
MONGO_DB: sharkinfo
MONGO_PORT: "27017"
kind: ConfigMap
metadata:
creationTimestamp: null
labels:
io.kompose.service: db-env
name: db-env
18 changes: 18 additions & 0 deletions db-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: v1
kind: Service
metadata:
annotations:
kompose.cmd: kompose convert
kompose.version: 1.18.0 (06a2e56)
creationTimestamp: null
labels:
io.kompose.service: db
name: db
spec:
ports:
- port: 27017
targetPort: 27017
selector:
io.kompose.service: db
status:
loadBalancer: {}
26 changes: 20 additions & 6 deletions db.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
const mongoose = require('mongoose');

const MONGO_USERNAME = 'sammy';
const MONGO_PASSWORD = 'password';
const MONGO_HOSTNAME = '127.0.0.1';
const MONGO_PORT = '27017';
const MONGO_DB = 'sharkinfo';
const {
MONGO_USERNAME,
MONGO_PASSWORD,
MONGO_HOSTNAME,
MONGO_PORT,
MONGO_DB
} = process.env;

const options = {
useNewUrlParser: true,
reconnectTries: Number.MAX_VALUE,
reconnectInterval: 500,
connectTimeoutMS: 10000,
};

const url = `mongodb://${MONGO_USERNAME}:${MONGO_PASSWORD}@${MONGO_HOSTNAME}:${MONGO_PORT}/${MONGO_DB}?authSource=admin`;

mongoose.connect(url, {useNewUrlParser: true});
mongoose.connect(url, options).then( function() {
console.log('MongoDB is connected');
})
.catch( function(err) {
console.log(err);
});
14 changes: 14 additions & 0 deletions dbdata-persistentvolumeclaim.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
creationTimestamp: null
labels:
io.kompose.service: dbdata
name: dbdata
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 100Mi
status: {}
42 changes: 42 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
version: '3'

services:
nodejs:
image: virgoinvincible/node-kubernetes
container_name: nodejs
restart: always
env_file: .env
environment:
- MONGO_USERNAME=$MONGO_USERNAME
- MONGO_PASSWORD=$MONGO_PASSWORD
- MONGO_HOSTNAME=db
- MONGO_PORT=$MONGO_PORT
- MONGO_DB=$MONGO_DB
ports:
- "80:8080"
volumes:
- .:/home/node/app
- node_modules:/home/node/app/node_modules
networks:
- app-network
command: ./wait-for.sh db:27017 -- /home/node/app/node_modules/.bin/nodemon app.js

db:
image: mongo:4.1.8-xenial
container_name: db
restart: always
env_file: .env
environment:
- MONGO_INITDB_ROOT_USERNAME=$MONGO_USERNAME
- MONGO_INITDB_ROOT_PASSWORD=$MONGO_PASSWORD
volumes:
- dbdata:/data/db
networks:
- app-network

networks:
app-network:
driver: bridge

volumes:
dbdata:
22 changes: 22 additions & 0 deletions docker-upload.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# USING BASH SCRIPT TO TAG AND UPLOAD AN IMAGE TO DOCKER HUB

#!/usr/bin/env bash

# Assumes that an image is built via `run_docker-compose.sh`

# Step 1:
# Create dockerpath
dockerpath=nodejs

# Step 2:
# Authenticate & tag
echo "Docker ID and Image: $dockerpath"
docker login -u virgoinvincible

#Step 3:
# Tag the images with your Docker ID
docker tag $dockerpath:latest virgoinvincible/$dockerpath

# Step 4:
# Push image to a docker repository
docker push virgoinvincible/$dockerpath
11 changes: 11 additions & 0 deletions hadolint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# USING BASH SCRIPT TO INSTALL HADOLINT

# Hadolint automates the detection of Dockerfile issues.
#This helps your Docker images adhere to best practices and organizational standards.

#!/usr/bin/env bash

# Installing Hadolint
sudo wget -O /bin/hadolint https://github.com/hadolint/hadolint/releases/download/v2.10.0/hadolint-Linux-x86_64

sudo chmod +x /bin/hadolint
15 changes: 15 additions & 0 deletions kompose.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Script on steps to install kubernetes kompose

#!/usr/bin/env bash

#installing binary file from a git hub repo
curl -L https://github.com/kubernetes/kompose/releases/download/v1.18.0/kompose-linux-amd64 -o kompose

#making binary executable
chmod +x kompose

#moving to PATH
sudo mv ./kompose /usr/local/bin/kompose

#verify installation
kompose version
30 changes: 30 additions & 0 deletions kubectl-install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# INSTALL KUBECTL BINARY WITH CURL ON LINUX

#!/usr/bin/env bash

# Step1:
# Download the latest release with the command
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"

# Step 2:
# Download the kubectl checksum file
curl -LO "https://dl.k8s.io/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl.sha256"

# Step 3:
# Validate the kubectl binary against the checksum file
echo "$(cat kubectl.sha256) kubectl" | sha256sum --check

# Step 4:
# Install kubectl
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl

# Step 5:
# Install kubectl to the ~/.local/bin director
chmod +x kubectl
mkdir -p ~/.local/bin
mv ./kubectl ~/.local/bin/kubectl
# and then append (or prepend) ~/.local/bin to $PATH

# Step 6:
# Test to ensure the version you installed is up-to-date
kubectl version --client --output=yaml
1 change: 1 addition & 0 deletions kubectl.sha256
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fcf86d21fb1a49b012bce7845cf00081d2dd7a59f424b28621799deceb5227b3
22 changes: 22 additions & 0 deletions minikube-install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# USING BASH SCRIPT TO INSTALL AND START A KUBERNETES CLUSTER

#!/usr/bin/env bash

# step 1:
# Installing minikube
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
sudo install minikube-linux-amd64 /usr/local/bin/minikube

# Step 2:
# Test the installation
minikube version

# Step 3:
# Start the kubernetes cluster
# minikube start
sudo minikube start --force

# Step 4:
# List kubernetes pods
# minikube kubectl -- get pods -A
sudo minikube kubectl -- get pods -A
Binary file added minikube-linux-amd64
Binary file not shown.
14 changes: 14 additions & 0 deletions node-modules-persistentvolumeclaim.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
creationTimestamp: null
labels:
io.kompose.service: node-modules
name: node-modules
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 100Mi
status: {}
14 changes: 14 additions & 0 deletions nodejs-claim0-persistentvolumeclaim.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
creationTimestamp: null
labels:
io.kompose.service: nodejs-claim0
name: nodejs-claim0
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 100Mi
status: {}
Loading