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

CI/CD Development #225

Closed
wants to merge 8 commits into from
Closed
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
7 changes: 7 additions & 0 deletions .bump2version.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[bumpversion]
commit = False
tag = False

[bumpversion:file:trails-viz-api/trailsvizapi/__init__.py]
search = __version__ = "{current_version}"
replace = __version__ = "{new_version}"
Empty file modified .gitattributes
100644 → 100755
Empty file.
119 changes: 119 additions & 0 deletions .github/workflows/backendCICD.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
name: API CI/CD (Backend)
on:
push:
branches:
- master
paths:
- 'trails-viz-api/**'
pull_request:
branches:
- master
paths:
- 'trails-viz-api/**'

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up python
uses: actions/setup-python@v3
with:
python-version: '3.7'

- name: Install dependencies
run: |
set -e
python -m pip install --upgrade pip
pip install flake8
pip install wheel
cd trails-viz-api
pip install -r requirements.txt

- name: Run flake8 and build project
run: |
set -e
cd trails-viz-api
flake8 . --count --max-line-length=119 --exclude trailsvizapi/__init__.py --show-source --statistics
python setup.py bdist_wheel

# - name: Upload build artifact # save the dist folder as an artifact
# if: github.event_name == 'push'
# uses: actions/upload-artifact@v4
# with:
# name: trails-viz-api-dist
# path: trails-viz-api/dist

deploy:
needs: build
runs-on: ubuntu-latest
if: github.event_name == 'push' # only deploy on push event
steps:
- name: Checkout code
uses: actions/checkout@v3

# - name: Download build artifact # download the dist folder from build
# uses: actions/download-artifact@v4
# with:
# name: trails-viz-api-dist
# path: trails-viz-api/dist

- name: Setup git user identity
run: |
git config --global user.name "outdoorrd-bot"
git config --global user.email "[email protected]"

- name: Update app version
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -e
commit_message=$(git log -1 --pretty=%B) # Get commit message
git checkout master
cd trails-viz-api/trailsvizapi
echo "Updating version..."
if [[ "$commit_message" == *"release=major"* ]]; then
bump2version major
elif [[ "$commit_message" == *"release=minor"* ]]; then
bump2version minor
elif [[ "$commit_message" == *"release=patch"* ]]; then
bump2version patch
else
bump2version patch
fi

# update the api version in __init__.py
# git checkout master
# cd trails-viz-api
# sed -i "s/__version__.*/__version__ = '$new_version'/" trailsvizapi/__init__.py
# cd ..
# echo "local version bump successful $new_version"
new_version=$(sed -n "s/__version__ = '\(.*\)'/\1/p" __init__.py)
git add trails-viz-api/trailsvizapi/__init__.py
git commit -m "Auto update version to $new_version"
echo "commited after version update"
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git
git push origin master
git tag "api-v$new_version"
git push origin --tags
echo "pushed new version to master"

- name: Deploy to Digital Ocean Droplet
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.DROPLET_IP }}
username: ${{ secrets.SSH_USERNAME }} # Update to use nginx user
key: ${{ secrets.DROPLET_SSH_KEY }}
script: |
cd trails-viz/
git pull origin master
conda activate trails-viz-api
cd trails-viz-api/
pip install --upgrade pip
pip install -r requirements.txt
cd docker-conf/
chmod +x ./start.sh
./start.sh
103 changes: 103 additions & 0 deletions .github/workflows/frontendCICD.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
name: APP CI/CD (Frontend)
on:
push:
branches:
- master
paths:
- 'trails-viz-app/**'
pull_request:
branches:
- master
paths:
- 'trails-viz-app/**'

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '12'

- name: Install dependencies
run: |
cd trails-viz-app
npm install

- name: Run lint and build project
run: |
set -e
cd trails-viz-app
npm run lint
npm run build

- name: Upload build artifact # save the dist folder as an artifact
if: github.event_name == 'push'
uses: actions/upload-artifact@v4
with:
name: trails-viz-app-dist
path: trails-viz-app/dist

deploy:
needs: build
runs-on: ubuntu-latest
if: github.event_name == 'push' # only deploy on push event
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Download build artifact # download the dist folder from build
uses: actions/download-artifact@v4
with:
name: trails-viz-app-dist
path: trails-viz-app/dist

- name: Setup git user identity
run: |
git config --global user.name "outdoorrd-bot"
git config --global user.email "[email protected]"

- name: Update app version
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -e
commit_message=$(git log -1 --pretty=%B) # Get commit message
echo "Updating version..."
if [[ "$commit_message" == *"release=major"* ]]; then
version_bump="major"
elif [[ "$commit_message" == *"release=minor"* ]]; then
version_bump="minor"
elif [[ "$commit_message" == *"release=patch"* ]]; then
version_bump="patch"
else
version_bump="patch"
fi

# update the version in package.json as it's the easiest thing to do using npm
git checkout master
cd trails-viz-app
new_version=$(npm version $version_bump) # this returs the new version number with 'v' as prefix
cd ..

echo "local version bump successful $new_version"
git add trails-viz-app/package.json
git add trails-viz-app/package-lock.json
git commit -m "Auto update version to $new_version"
echo "commited after version update"
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git
git push origin master
git tag "app-v$new_version"
git push origin --tags
echo "pushed new version to master"

- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: trails-viz-app/dist
Empty file modified .gitignore
100644 → 100755
Empty file.
Empty file modified .travis.yml
100644 → 100755
Empty file.
Empty file modified Dockerfile
100644 → 100755
Empty file.
Empty file modified README.md
100644 → 100755
Empty file.
Empty file modified build.sh
100644 → 100755
Empty file.
14 changes: 8 additions & 6 deletions docker-conf/default.conf
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
server {
listen 80;
server_name trailtrends.outdoorrd.org;
listen 8080;
#server_name trailtrends.outdoorrd.org;
server_name localhost;
return 301 https://$server_name$request_uri;
}

server {
listen 443 ssl;
server_name trailtrends.outdoorrd.org;
listen 8443 ssl;
#server_name trailtrends.outdoorrd.org;
server_name localhost;
ssl_certificate /app/credentials/outdoorrd-public.crt;
ssl_certificate_key /app/credentials/outdoorrd-private.pem;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
Expand All @@ -23,7 +25,7 @@ server {
}

location /api {
include uwsgi_params;
include /etc/nginx/uwsgi_params;
uwsgi_pass unix:/app/trailsvizapi.sock;
}

Expand Down Expand Up @@ -58,4 +60,4 @@ server {
#location ~ /\.ht {
# deny all;
#}
}
}
7 changes: 3 additions & 4 deletions docker-conf/nginx.conf
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

user nginx;
worker_processes 1;
worker_processes auto;

error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
Expand Down Expand Up @@ -33,5 +32,5 @@ http {
gzip_types text/plain text/css text/xml text/javascript application/javascript application/json application/x-javascript application/xml;
gzip_disable "MSIE [1-6]\.";

include /etc/nginx/conf.d/*.conf;
}
include /home/nginx/trails-viz/docker-conf/default.conf;
}
32 changes: 30 additions & 2 deletions docker-conf/start.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,31 @@
#!/bin/bash -e
uwsgi /app/uwsgi-config.ini &
nginx -g 'daemon off;'

# Stop running nginx and uWSGI processes
pkill nginx || echo "nginx not running"
pkill uwsgi || echo "uWSGI not running"

# Start uWSGI
/home/nginx/miniconda3/envs/trails-viz-api/bin/uwsgi --ini /home/nginx/trails-viz/trails-viz-api/uwsgi-config.ini &

# Capture the PID of the uWSGI process
UWSGI_PID=$!

# Start nginx
nginx -c /home/nginx/trails-viz/docker-conf/nginx.conf -g 'daemon off;' &

# Capture the PID of the nginx process
NGINX_PID=$!

# Function to handle termination signals
cleanup() {
echo "Stopping services..."
kill -TERM "$UWSGI_PID" "$NGINX_PID"
wait "$UWSGI_PID" "$NGINX_PID"
echo "Services stopped."
}

# Trap termination signals
trap cleanup SIGINT SIGTERM

# Wait for the services to exit
wait "$UWSGI_PID" "$NGINX_PID"
Empty file modified trails-viz-api/.coveragerc
100644 → 100755
Empty file.
Empty file modified trails-viz-api/.gitignore
100644 → 100755
Empty file.
Empty file modified trails-viz-api/requirements.txt
100644 → 100755
Empty file.
1 change: 0 additions & 1 deletion trails-viz-api/setup.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
with open('requirements.txt', 'r') as req:
requirements = req.readlines()


PACKAGE_NAME = 'trailsvizapi'
VERSION = trailsvizapi.__version__

Expand Down
Empty file modified trails-viz-api/trailsvizapi/__init__.py
100644 → 100755
Empty file.
Empty file modified trails-viz-api/trailsvizapi/config/__init__.py
100644 → 100755
Empty file.
Empty file modified trails-viz-api/trailsvizapi/config/app_config.py
100644 → 100755
Empty file.
Empty file modified trails-viz-api/trailsvizapi/config/auth.py
100644 → 100755
Empty file.
Empty file modified trails-viz-api/trailsvizapi/controller/__init__.py
100644 → 100755
Empty file.
Empty file modified trails-viz-api/trailsvizapi/controller/estimates.py
100644 → 100755
Empty file.
Empty file modified trails-viz-api/trailsvizapi/controller/home_locations.py
100644 → 100755
Empty file.
Empty file modified trails-viz-api/trailsvizapi/controller/projects.py
100644 → 100755
Empty file.
Empty file modified trails-viz-api/trailsvizapi/controller/users_controller.py
100644 → 100755
Empty file.
Empty file modified trails-viz-api/trailsvizapi/controller/visitation.py
100644 → 100755
Empty file.
Empty file modified trails-viz-api/trailsvizapi/repository/__init__.py
100644 → 100755
Empty file.
Empty file modified trails-viz-api/trailsvizapi/repository/estimates.py
100644 → 100755
Empty file.
Empty file modified trails-viz-api/trailsvizapi/repository/home_locations.py
100644 → 100755
Empty file.
Empty file modified trails-viz-api/trailsvizapi/repository/prepare_data.py
100644 → 100755
Empty file.
Empty file modified trails-viz-api/trailsvizapi/repository/projects_and_sites.py
100644 → 100755
Empty file.
Empty file modified trails-viz-api/trailsvizapi/repository/users_repository.py
100644 → 100755
Empty file.
Empty file modified trails-viz-api/trailsvizapi/repository/visitation.py
100644 → 100755
Empty file.
9 changes: 9 additions & 0 deletions trails-viz-api/uwsgi-config.ini
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
[uwsgi]
chdir = /home/nginx/trails-viz/trails-viz-api
home = /home/nginx/miniconda3/envs/trails-viz-api

socket = /app/trailsvizapi.sock
module = trailsvizapi
callable = app
Expand All @@ -10,3 +13,9 @@ chmod-socket = 777
vacuum = true

die-on-term = true
enable-threads = true

# environment variables
; env = FLASK_APP=trailsvizapi
; env = FLASK_ENV=development
; env = DATA_FILES_ROOT=/home/davye/RecSetGo/dashboard_data/trails-viz-data
Empty file modified trails-viz-app/.env.development
100644 → 100755
Empty file.
Empty file modified trails-viz-app/.env.production
100644 → 100755
Empty file.
Empty file modified trails-viz-app/.gitignore
100644 → 100755
Empty file.
Empty file modified trails-viz-app/babel.config.js
100644 → 100755
Empty file.
Empty file modified trails-viz-app/package-lock.json
100644 → 100755
Empty file.
Empty file modified trails-viz-app/package.json
100644 → 100755
Empty file.
Empty file modified trails-viz-app/public/favicon.ico
100644 → 100755
Empty file.
Empty file modified trails-viz-app/public/index.html
100644 → 100755
Empty file.
1 change: 0 additions & 1 deletion trails-viz-app/src/App.vue
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export default {
},
mounted() {
let self = this;

// add interceptor to show modal when 403 response is received
axios.interceptors.response.use(
response => response,
Expand Down
Empty file modified trails-viz-app/src/assets/C3.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified trails-viz-app/src/assets/ForestServiceLogoOfficial.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified trails-viz-app/src/assets/TNC.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified trails-viz-app/src/assets/US-NationalParkService.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified trails-viz-app/src/assets/logo.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified trails-viz-app/src/assets/natcap.jpg
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified trails-viz-app/src/assets/styles/home-locations-map.css
100644 → 100755
Empty file.
Empty file modified trails-viz-app/src/components/Administration.vue
100644 → 100755
Empty file.
Empty file modified trails-viz-app/src/components/BarGraph.vue
100644 → 100755
Empty file.
Empty file modified trails-viz-app/src/components/Dashboard.vue
100644 → 100755
Empty file.
Empty file modified trails-viz-app/src/components/DemographicsSummary.vue
100644 → 100755
Empty file.
Empty file modified trails-viz-app/src/components/HomeLocations.vue
100644 → 100755
Empty file.
Empty file modified trails-viz-app/src/components/HomeLocationsMap.vue
100644 → 100755
Empty file.
Empty file modified trails-viz-app/src/components/InfoViewer.vue
100644 → 100755
Empty file.
Empty file modified trails-viz-app/src/components/LandingPage.vue
100644 → 100755
Empty file.
Empty file modified trails-viz-app/src/components/Login.vue
100644 → 100755
Empty file.
Empty file modified trails-viz-app/src/components/MapDiv.vue
100644 → 100755
Empty file.
Empty file modified trails-viz-app/src/components/TimeSeries.vue
100644 → 100755
Empty file.
Empty file modified trails-viz-app/src/components/TopBar.vue
100644 → 100755
Empty file.
Empty file modified trails-viz-app/src/components/UserProfile.vue
100644 → 100755
Empty file.
Empty file modified trails-viz-app/src/cookie.js
100644 → 100755
Empty file.
Empty file modified trails-viz-app/src/event-bus.js
100644 → 100755
Empty file.
Empty file modified trails-viz-app/src/main.js
100644 → 100755
Empty file.
Empty file modified trails-viz-app/src/router.js
100644 → 100755
Empty file.
Empty file modified trails-viz-app/src/store/constants.js
100644 → 100755
Empty file.
Empty file modified trails-viz-app/src/store/index.js
100644 → 100755
Empty file.
Empty file modified trails-viz-app/src/store/vectors.js
100644 → 100755
Empty file.
4 changes: 2 additions & 2 deletions trails-viz-app/vue.config.js
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module.exports = {
publicPath: '/'
};
publicPath: process.env.NODE_ENV === 'production' ? '/trails-viz/' : '/'
};
Loading