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

[WIP] Implement Github Actions CI/CD Pipeline #465

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
efa207d
Fixed bootstrap table not showing and other minor bugs
maheshkasabe Jun 3, 2023
e258f1e
Added Local dockerfile & docker-compose support
maheshkasabe Jun 8, 2023
0b93870
Added enviornment variables inside docker-compose setup and developme…
maheshkasabe Jun 11, 2023
d292024
Added an ECR Build & Deploy workflow
maheshkasabe Jun 11, 2023
efee21f
Added elasticsearch support for docker-compose file & deploy workflow
maheshkasabe Jun 21, 2023
6cfc7b0
Added environment variable support for production file
maheshkasabe Jun 25, 2023
9d1336b
Some additions to Production file
maheshkasabe Jun 26, 2023
9249d89
Added some comments for better understanding
maheshkasabe Jun 30, 2023
f8ce6e9
Added some extra workflows for quality & labeling
maheshkasabe Jul 2, 2023
cc653d8
Removed docker-compose volume to install bower compoenents
maheshkasabe Jul 2, 2023
20fa485
updated postgres version and added libpq-dev package
maheshkasabe Jul 3, 2023
acf602b
Mac docker install issues resolved
maheshkasabe Jul 8, 2023
0c5b156
Added Trivy Scanner
maheshkasabe Jul 19, 2023
2910aba
Added some extra imporvements
maheshkasabe Jul 19, 2023
c815599
Added dockerhub ci workflow
maheshkasabe Jul 24, 2023
95d2d23
Added workflow rule to push image only on merging to master branch
maheshkasabe Jul 24, 2023
a41879e
Added Comments
maheshkasabe Aug 5, 2023
7ca2918
Added some more comments
maheshkasabe Aug 5, 2023
4f4cb0f
added a actions-pipeline inside pr-labeler.yml
maheshkasabe Aug 6, 2023
55c9812
Renamed workflow
maheshkasabe Aug 6, 2023
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
14 changes: 14 additions & 0 deletions .github/auto_assign.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Set to true to add reviewers to pull requests
addReviewers: true

# Set to true to add assignees to pull requests
addAssignees: false

# A list of reviewers to be added to pull requests (GitHub user name)
reviewers:
- adbharadwaj # Aditya Bharadwaj
#(optional) - tmmurali

# A number of reviewers added to the pull request
# Set 0 to add all the reviewers (default: 0)
numberOfReviewers: 0
4 changes: 4 additions & 0 deletions .github/pr-labeler.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
feature: ['feature/*', 'feat/*']
fix: fix/*
chore: chore/*
actions-pipeline: actions-pipeline/*
24 changes: 24 additions & 0 deletions .github/workflows/Image_scan.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Trivy Docker Image Scan

on: [push, pull_request] # Runs when the someone pushes changes to branch or creates a pull request

jobs:
build:
name: Build
runs-on: ubuntu-20.04
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Build an image from Dockerfile
run: docker build -t docker.io/my-organization/my-app:${{ github.sha }} .

- name: Run Trivy vulnerability scanner # Runs the Trivy Vulnerability Scanner and Prints the results
uses: aquasecurity/trivy-action@master
with:
image-ref: 'docker.io/my-organization/my-app:${{ github.sha }}'
format: 'table'
exit-code: '0'
ignore-unfixed: true
vuln-type: 'os,library'
severity: 'CRITICAL,HIGH'
13 changes: 13 additions & 0 deletions .github/workflows/assign_pr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: 'Auto Assign'
on:
pull_request_target:
types: [opened, ready_for_review] # Runs when the someone opens a pull request

jobs:
add-reviews:
runs-on: ubuntu-latest
steps:
- name: Auto Assign Reviewer # Assigns Reviwer from reviewers list to the Pull Request
uses: kentaro-m/[email protected]
with:
configuration-path: '.github/auto_assign.yml' # Only needed if you use something other than .github/auto_assign.yml
32 changes: 32 additions & 0 deletions .github/workflows/ci-graphspace.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Docker Build & Push Graphspace

on: [push, pull_request] # Runs when the someone pushes changes to branch or creates a pull request

jobs:

build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: login to docker hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}

- name: Set Tag
id: vars
if: ${{ github.ref == 'refs/heads/master' }}
run: echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT

- name: Create Graphspace image
run: docker build -t graphspace .

- name: Push image to Dockerhub
if: ${{ github.ref == 'refs/heads/master' }}
run: |
docker tag graphspace maheshkasbe/graphspace:${{ steps.vars.outputs.sha_short }}
docker tag graphspace maheshkasbe/graphspace:latest
docker push maheshkasbe/graphspace:latest
docker push maheshkasbe/graphspace:${{ steps.vars.outputs.sha_short }}
48 changes: 48 additions & 0 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Push to ECR

on: [push, pull_request] # Runs when the someone pushes changes to branch or creates a pull request

jobs:
deploy:
runs-on: ubuntu-latest
steps:

- name: Check out code
uses: actions/checkout@v2

- name: Build the Docker-compose file
run: docker-compose -f "docker-compose.yaml" up -d --build

- name: Show containers
run: docker ps -a

- name: Configure AWS credentials
if: ${{ github.ref == 'refs/heads/master' }}
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1

- name: Login to Amazon ECR
if: ${{ github.ref == 'refs/heads/master' }}
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
with:
registry-type: public

- name: Set Tag
id: vars
if: ${{ github.ref == 'refs/heads/master' }}
run: echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT

- name: Build, tag, and push image to Amazon ECR
if: ${{ github.ref == 'refs/heads/master' }}
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
REGISTRY_ALIAS: ${{ secrets.AWS_REGISTRY_ALIAS }}
ECR_REPOSITORY: ${{ secrets.AWS_ECR_REPOSITORY }}
IMAGE_TAG: ${{ steps.vars.outputs.sha_short }}
run: |
docker build -t $ECR_REGISTRY/$REGISTRY_ALIAS/$ECR_REPOSITORY:$IMAGE_TAG .
docker push $ECR_REGISTRY/$REGISTRY_ALIAS/$ECR_REPOSITORY:$IMAGE_TAG
15 changes: 15 additions & 0 deletions .github/workflows/issue_label.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Labeling new issue
on:
issues:
types: ['opened','edited']
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Issue Label #Labels the issue by the description of the issue
uses: Renato66/auto-label@v2
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
ignore-comments: true
labels-synonyms: '{"bug":["error","need fix","not working"],"enhancement":["upgrade"],"question":["help"]}'
labels-not-allowed: '["good first issue"]'
32 changes: 32 additions & 0 deletions .github/workflows/pr_labeler.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: PR Labeler
on: pull_request_target # Runs when the someone creates a pull request

permissions:
contents: read
pull-requests: write

jobs:
pr-labeler:
runs-on: ubuntu-latest

steps:
- name: branch-label # Labels the Pull Request by branch name as which branch the pr is raised to
uses: TimonVS/pr-labeler-action@v4
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
configuration-path: .github/pr-labeler.yml # optional, .github/pr-labeler.yml is the default value

- name: size-label # Labels the Pull Request by the no of lines of code
uses: "pascalgn/[email protected]"
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
with:
sizes: >
{
"0": "XS",
"20": "S",
"50": "M",
"200": "L",
"800": "XL",
"2000": "XXL"
}
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

# Ignore updates to production.py,
# It's meant to be local
production.py

# Ignore Mac DS_Store files
.DS_Store
Expand Down
31 changes: 31 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#Base Image to install & Run Graphspace
FROM ubuntu:18.04

#Created a app directory for graphspace
WORKDIR /app

#Installs required & dev packages to smoothly install graphspace rquirements on ubuntu and mac as well
RUN apt-get -y update && apt-get install -y \
npm \
git \
libpq-dev \
libxml2 \
libxslt-dev

#Installs npm globally
RUN npm install bower -g

#Installs Pip package and upgrades it
RUN apt-get install -y python-pip && pip install --upgrade pip

#Copies whole graphspace project in app directory
COPY . /app

#Installs Graphspace requirements
RUN pip install -r requirements.txt

#Installs Graphspace
RUN sh install.sh

#Exposes the port 8000 to discover graphspace container
EXPOSE 8000
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Requirements
Installation Instructions
===================================
* [Running GraphSpace Locally](https://github.com/Murali-group/GraphSpace/wiki/Running-GraphSpace-locally)
* [Running Graphspace Locally using Docker & Docker‐Compose](https://github.com/Murali-group/GraphSpace/wiki/Running-Graphspace-using-Docker-&-Docker‐Compose)
* [Running GraphSpace on Apache](https://github.com/Murali-group/GraphSpace/wiki/Running-GraphSpace-on-Apache)

Documentation
Expand Down
2 changes: 0 additions & 2 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,9 @@
"animate.css": "^3.5.2",
"cytoscape": "^2.7.11",
"webcola": "^3.3.0",
"bootstrap": "^3.3.7",
"cytoscape-cola": "^1.6.0",
"intro.js": "^2.4.0",
"jquery-ui": "^1.12.1",
"bootstrap-table": "^1.11.0",
"cytoscape-panzoom": "^2.4.0",
"select2": "select2-dist#^4.0.3",
"cytoscape-context-menus": "^2.1.1",
Expand Down
9 changes: 9 additions & 0 deletions db.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!bin/sh

#connects to the postgres database & creates pg_trgm & btree_gin extensions
echo "enabling pg_trgm & btree_gin on database $POSTGRES_DB"
psql -U $POSTGRES_USER --dbname="$POSTGRES_DB" <<-'EOSQL'
create extension if not exists pg_trgm;
create extension if not exists btree_gin;
EOSQL
echo "finished with exit code $?"
15 changes: 15 additions & 0 deletions docker-compose.prod.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: "3.4"
services:
graphspace:
restart: always
stdin_open: true # docker run -i
tty: true # docker run -t
build:
context: .
ports:
- "8000:8000"
env_file:
- ./secrets.env
command: >
sh -c "python manage.py migrate &&
python manage.py runserver"
52 changes: 52 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
version: "3.4"
services:
#Postgres container with env variables
db:
image: postgres:9.6
restart: always
environment:
POSTGRES_DB: graphspace
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
ports:
- "5432:5432"
volumes:
- pgdata:/var/lib/PostgreSQL/data
- ./db.sh:/docker-entrypoint-initdb.d/create_extensions.sh

#Elasticsearch Container
elasticsearch:
restart: always
image: docker.elastic.co/elasticsearch/elasticsearch:7.5.2
ports:
- "9200:9200"
environment:
- discovery.type=single-node
volumes:
- esdata:/var/lib/elasticsearch/data

#Graphspace Image with enviornment variables
graphspace:
restart: always
image: maheshkasbe/graphspace:latest
environment:
POSTGRES_HOST: db
POSTGRES_DB: graphspace
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
stdin_open: true # docker run -i
tty: true # docker run -t
# build:
# context: .
ports:
- "8000:8000"
command: >
sh -c "python manage.py migrate --settings=graphspace.settings.local &&
python manage.py runserver 0.0.0.0:8000 --settings=graphspace.settings.local"
depends_on:
- db
- elasticsearch

volumes:
pgdata:
esdata:
3 changes: 2 additions & 1 deletion graphspace/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@
)

BASE = declarative_base()
ELASTIC_CLIENT = Elasticsearch()
# for connecting with elasticsearch client using hostname and port
ELASTIC_CLIENT = Elasticsearch(['elasticsearch:9200'])

LOGGING = {
'version': 1,
Expand Down
10 changes: 5 additions & 5 deletions graphspace/settings/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@
# http://stackoverflow.com/questions/4642011/test-sending-email-without-email-server
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'


# Added enviornment variable option to run with doccker-compose file and also with local dev setup
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'test_database',
'USER': 'adb',
'PASSWORD': '',
'HOST': 'localhost',
'NAME': os.environ.get('POSTGRES_DB', 'graphspace'),
'USER': os.environ.get('POSTGRES_USER', 'postgres'),
'PASSWORD': os.environ.get('POSTGRES_PASSWORD', 'postgres'),
'HOST': os.environ.get('POSTGRES_HOST', 'localhost'),
'PORT': '5432'
}
}
Loading