Fakultas Ilmu Komputer UI

Commit c3c68712 authored by Bayukanta Iqbal Gunawan's avatar Bayukanta Iqbal Gunawan Committed by BIMO IMAN SMARTADI
Browse files

Dockerfile to staging

parent e94a9f10
variables:
POSTGRES_DB: $DB_NAME
POSTGRES_USER: $DB_USER
POSTGRES_PASSWORD: $DB_PASSWORD
POSTGRES_HOST_AUTH_METHOD: $DB_HOST_AUTH_METHOD
services:
- postgres:12.2-alpine
stages:
- test
- linter
- sonarqube
- deploy
- staging
- production
UnitTest:
image: python:3.7
stage: test
only:
refs:
- staging
coverage: '/TOTAL\s+\d+\s+\d+\s+(\d+)%/'
before_script:
- pip install -r requirements.txt
......@@ -24,6 +37,9 @@ UnitTest:
Pylint:
image: python:3.7
stage: linter
only:
refs:
- staging
allow_failure: true
before_script:
- pip install -r requirements.txt
......@@ -36,6 +52,9 @@ SonarScanner:
name: sonarsource/sonar-scanner-cli:latest
entrypoint: [""]
stage: sonarqube
only:
refs:
- staging
script:
- sonar-scanner
-Dsonar.host.url=https://pmpl.cs.ui.ac.id/sonarqube
......@@ -45,7 +64,7 @@ SonarScanner:
Staging:
image: ruby:2.4
stage: deploy
stage: staging
only:
refs:
- staging
......@@ -63,17 +82,27 @@ Staging:
Deployment:
image: ruby:2.4
stage: deploy
stage: production
only:
refs:
- master
before_script:
- gem install dpl
- wget -qO- https://cli-assets.heroku.com/install-ubuntu.sh | sh
- apt-get update -qq
- apt-get install -qq git
- 'which ssh-agent || ( apt-get install -qq openssh-client )'
- eval $(ssh-agent -s)
- ssh-add <(echo $SSH_PRIVATE_KEY | base64 -d)
- mkdir -p ~/.ssh
- '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
script:
- dpl --provider=heroku --app=$HEROKU_APPNAME --api-key=$HEROKU_APIKEY
- export HEROKU_API_KEY=$HEROKU_APIKEY
- heroku run --app $HEROKU_APPNAME migrate
- >
ssh admin@10.119.106.23
"cd poipole-dtb-beasiswa-miskin-dan-disabilitas &&
git checkout master &&
git pull origin master &&
bash stop.sh &&
bash start.sh &&
exit"
environment:
name: production
url: $HEROKU_APP_HOST
url: $VM_URL
FROM python:latest
WORKDIR /opt/pplbackend
RUN mkdir -p /opt/pplbackend
ADD . /opt/pplbackend
ENV HTTP_PROXY="http://proxy.cs.ui.ac.id:8080"
ENV http_proxy="http://proxy.cs.ui.ac.id:8080"
ENV HTTPS_PROXY="http://proxy.cs.ui.ac.id:8080"
ENV https_proxy="http://proxy.cs.ui.ac.id:8080"
RUN\
python3 -m pip install -r requirements.txt --no-cache-dir
RUN chmod +x /opt/pplbackend/docker_start.sh
EXPOSE 8000
version: "3"
services:
pplbackend:
build: .
restart: always
entrypoint: /opt/pplbackend/docker_start.sh
environment:
- DB_NAME=bisago
- DB_USER=bisago
- DB_PASSWORD=poipole
- DB_HOST=bisago_db
- DB_PORT=5432
ports:
- "80:8000"
depends_on:
- bisago_db
bisago_db:
image: postgres
restart: always
ports:
- "5432"
environment:
- POSTGRES_DB=bisago
- POSTGRES_USER=bisago
- POSTGRES_PASSWORD=poipole
#!/bin/bash
python3 manage.py makemigrations rest_framework_jwt
python3 manage.py migrate
gunicorn pplbackend.wsgi --bind 0.0.0.0:8000
\ No newline at end of file
......@@ -97,8 +97,12 @@ WSGI_APPLICATION = 'pplbackend.wsgi.application'
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': os.environ.get('DB_NAME', 'postgres'),
'USER': os.environ.get('DB_USER', 'postgres'),
'PASSWORD': os.environ.get('DB_PASSWORD', 'postgres'),
'HOST': os.environ.get('DB_HOST', 'localhost'),
'PORT': os.environ.get('DB_PORT', '5432'),
}
}
......
argon2-cffi==19.2.0
astroid==2.4.0
cachetools==4.0.0
certifi==2018.8.24
cffi==1.14.0
chardet==3.0.4
colorama==0.3.9
coverage==4.4.1
defusedxml==0.6.0
dj-database-url==0.4.2
Django==2.1.5
django-allauth==0.41.0
......@@ -29,7 +21,7 @@ mccabe==0.6.1
oauthlib==3.1.0
Pillow==7.0.0
pip==20.0.2
psycopg2==2.8.5
psycopg2-binary==2.8.5
pyasn1==0.4.8
pyasn1-modules==0.2.8
pycparser==2.19
......
#!/bin/bash
echo "Starting bisago ..."
env/bin/pip3 install -r requirements.txt
env/bin/python3 manage.py migrate
sudo env/bin/python3 manage.py runserver 0:80 >out 2>&1 &
#!/bin/bash
PID=$(ps ax | grep manage.py | grep -v grep | head -n1 | awk '{print $1}')
if [[ $PID ]]
then
echo "Stopping bisago ..."
ps ax | grep manage.py | grep -v grep | head -n1 | awk '{print $1}' | xargs sudo kill -TERM
else
echo "bisago is not running ..."
fi
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment