Fakultas Ilmu Komputer UI

Verified Commit 137c3232 authored by Giovan Isa Musthofa's avatar Giovan Isa Musthofa
Browse files

Merge remote-tracking branch 'origin/staging' into PBI-2-register_and_login

parents 9f6d6c19 2a7cc8e0
Pipeline #38889 passed with stages
in 15 minutes and 14 seconds
......@@ -10,7 +10,7 @@ variables:
cache:
key: ${CI_COMMIT_REF_SLUG}
paths:
- frontend/node_modules/
- .npm
- .cache/pip/
DRF Unit Tests:
......@@ -35,8 +35,7 @@ Gatsby Unit Tests:
coverage: '/All files\s*\|\s*[\d\.]+\s*\|\s*[\d\.]+\s*\|\s*[\d\.]+\s*\|\s*([\d\.]+)/'
before_script:
- cd frontend
- npm install
- export PATH=$PATH:$(npm bin)
- npm ci --cache .npm --prefer-offline
script:
- npm run test
artifacts:
......@@ -59,8 +58,8 @@ Gatsby ESLint Lint:
image: node:12
before_script:
- cd frontend
- npm i -g eslint
- npm i eslint-plugin-prettier eslint-config-react-app @typescript-eslint/eslint-plugin@2.x @typescript-eslint/parser@2.x babel-eslint@10.x eslint@6.x eslint-plugin-flowtype@3.x eslint-plugin-import@2.x eslint-plugin-jsx-a11y@6.x eslint-plugin-react@7.x eslint-plugin-react-hooks@1.x
- npm install --cache .npm --prefer-offline -g eslint
- npm ci --cache .npm --prefer-offline
script:
- eslint .
only:
......@@ -119,44 +118,38 @@ DRF Static Deploy:
stage: deploy
image: node:12
tags:
- deploy
- public
needs:
- job: DRF Static Build
artifacts: true
before_script:
- npm install -g netlify-cli
- npm install -g --cache .npm --prefer-offline netlify-cli
script:
- netlify deploy --site=$NETLIFY_DRF_ID --dir=static_root/ --auth=$NETLIFY_DRF_AUTH --prod
only:
refs:
- master
- staging
changes:
- backend/**/*
- .gitlab-ci.yml
DRF Deploy Staging:
stage: deploy
tags:
- deploy
- no_proxy
image:
name: gcr.io/kaniko-project/executor:debug
entrypoint: [""]
needs: ["DRF Unit Tests"]
script:
- echo "{\"auths\":{\"https://index.docker.io/v1/\":{\"auth\":\"$CONTAINER_REGISTRY_AUTH\"}}}" > /kaniko/.docker/config.json
- /kaniko/executor --context $CI_PROJECT_DIR/backend/ --dockerfile $CI_PROJECT_DIR/backend/Dockerfile --destination "$CONTAINER_REGISTRY_PROJECT:$CI_COMMIT_REF_NAME"
- /kaniko/executor --context $CI_PROJECT_DIR/backend/ --dockerfile $CI_PROJECT_DIR/backend/dev.Dockerfile --destination "$CONTAINER_REGISTRY_PROJECT:$CI_COMMIT_REF_NAME"
only:
refs:
- staging
changes:
- backend/**/*
- .gitlab-ci.yml
DRF Deploy Production:
stage: deploy
tags:
- deploy
- no_proxy
image:
name: gcr.io/kaniko-project/executor:debug
entrypoint: [""]
......@@ -167,9 +160,6 @@ DRF Deploy Production:
only:
refs:
- master
changes:
- backend/**/*
- .gitlab-ci.yml
Gatsby Deploy Staging:
stage: deploy
......@@ -179,8 +169,8 @@ Gatsby Deploy Staging:
needs: ["Gatsby Unit Tests"]
before_script:
- cd frontend
- npm install
- npm install netlify-cli gatsby-cli -g
- npm ci --cache .npm --prefer-offline
- npm install --cache .npm --prefer-offline netlify-cli gatsby-cli -g
- GATSBY_ACTIVE_ENV=staging GATSBY_GOOGLE_CLIENT_ID=$GATSBY_GOOGLE_CLIENT_ID_STAGING gatsby build
script:
- netlify deploy --site=$NETLIFY_GATSBY_ID_STAGING --dir=public/ --auth=$NETLIFY_GATSBY_AUTH --prod
......@@ -196,8 +186,8 @@ Gatsby Deploy Production:
needs: ["Gatsby Unit Tests"]
before_script:
- cd frontend
- npm install
- npm install netlify-cli gatsby-cli -g
- npm ci --cache .npm --prefer-offline
- npm install --cache .npm --prefer-offline netlify-cli gatsby-cli -g
- GATSBY_ACTIVE_ENV=production GATSBY_GOOGLE_CLIENT_ID=$GATSBY_GOOGLE_CLIENT_ID_PRODUCTION gatsby build
script:
- netlify deploy --site=$NETLIFY_GATSBY_ID --dir=public/ --auth=$NETLIFY_GATSBY_AUTH --prod
......
README.md
Dockerfile
*Dockerfile
.dockerignore
**/__pycache__/*
.venv/
.env/
venv/
env/
.vscode/
.netlify/
static_root/
db.sqlite3
.coverage
coverage.xml
.flake8
.gitignore
sonar-project.properties
......@@ -3,9 +3,10 @@
.env/
venv/
env/
.vscode/
static_root/
.netlify/
db.sqlite3
.coverage
coverage.xml
.idea/
FROM python:3.8-buster
FROM python:3.8-alpine as builder
RUN apt-get update -q && \
apt-get install -y libpq-dev python3-dev
RUN apk add --no-cache postgresql-dev gcc python3-dev musl-dev
WORKDIR /app/
COPY requirements.txt ./
COPY requirements-prod.txt ./
RUN pip wheel --no-cache-dir \
--no-deps \
--wheel-dir /app/wheels \
-r requirements-prod.txt
FROM python:3.8-alpine
RUN apk add --no-cache libpq postgresql-client
WORKDIR /app
COPY requirements.txt /app/requirements.txt
COPY requirements-prod.txt /app/requirements-prod.txt
RUN pip install -r requirements-prod.txt
COPY --from=builder /app/wheels/ /wheels
RUN pip install --upgrade pip
RUN pip install --no-cache /wheels/*
COPY dblood/ /app/dblood/
COPY main/ /app/main/
COPY manage.py /app/
COPY . /app/
EXPOSE 8000
ENV DATABASE_URL 'sqlite:///db.sqlite3'
ENV DJANGO_SETTINGS_MODULE 'dblood.settings.production'
ENV DEBUG 'False'
CMD ["gunicorn", "dblood.wsgi", "--bind", "0.0.0.0:8000"]
......@@ -11,6 +11,6 @@ import os
from django.core.asgi import get_asgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'dblood.settings')
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'dblood.settings.production')
application = get_asgi_application()
......@@ -21,19 +21,6 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = os.environ.get(
'SECRET_KEY', '__super_secret_high_entropy_pseudo_random_bytes_a608e1fb__')
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = os.getenv('DEBUG', 'True') != 'False'
if DEBUG:
ALLOWED_HOSTS = ['*']
else:
ALLOWED_HOSTS = os.getenv('ALLOWED_HOSTS', 'localhost').split(';')
# Application definition
INSTALLED_APPS = [
......@@ -44,13 +31,13 @@ INSTALLED_APPS = [
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'anymail',
'corsheaders',
'rest_framework_authlib',
'main',
'stok_darah',
'anymail',
'django_extensions',
'corsheaders',
'donor'
'donor',
]
MIDDLEWARE = [
......@@ -137,7 +124,7 @@ AUTH_PASSWORD_VALIDATORS = [
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
TIME_ZONE = 'Asia/Jakarta'
USE_I18N = True
......@@ -149,10 +136,7 @@ USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.0/howto/static-files/
if DEBUG:
STATIC_URL = '/static/'
else:
STATIC_URL = os.getenv('STATIC_URL', 'https://dblood-api.netlify.com/')
STATIC_URL = os.getenv('STATIC_URL', 'https://dblood-api.netlify.com/')
STATIC_ROOT = 'static_root/'
......@@ -162,14 +146,6 @@ CORS_ORIGIN_WHITELIST = [
"https://dblood.netlify.com",
]
if DEBUG:
REST_CLIENT_SITE = 'http://localhost:8000'
else:
REST_CLIENT_SITE = 'https://dblood.netlify.com'
REST_CLIENT_SITE = os.getenv('REST_CLIENT_SITE', REST_CLIENT_SITE)
# REST Framework settings
REST_FRAMEWORK = {
......
from .common import *
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = os.getenv('SECRET_KEY')
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = os.getenv('DEBUG', 'True') != 'False'
ALLOWED_HOSTS = os.getenv('ALLOWED_HOSTS', 'localhost').split(';')
# Application definition
STATIC_URL = os.getenv('STATIC_URL', 'https://dblood-api.netlify.app/')
REST_CLIENT_SITE = 'https://dblood.netlify.app'
REST_CLIENT_SITE = os.getenv('REST_CLIENT_SITE', REST_CLIENT_SITE)
from .production import *
SECRET_KEY = os.getenv('SECRET_KEY', '__super_secret_high_entropy_pseudo_random_bytes_a608e1fb__')
DEBUG = True
ALLOWED_HOSTS = ['*']
# Application definition
INSTALLED_APPS.extend([
'django_extensions',
])
STATIC_URL = '/static/'
REST_CLIENT_SITE = 'http://localhost:8000'
REST_CLIENT_SITE = os.getenv('REST_CLIENT_SITE', REST_CLIENT_SITE)
......@@ -11,6 +11,6 @@ import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'dblood.settings')
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'dblood.settings.production')
application = get_wsgi_application()
FROM python:3.8-buster
RUN apt-get update -q && \
apt-get install -y libpq-dev python3-dev
WORKDIR /app
COPY requirements.txt /app/
COPY requirements-dev.txt /app/
RUN pip install -r requirements-dev.txt
COPY . /app/
EXPOSE 8000
ENV DATABASE_URL 'sqlite:///db.sqlite3'
RUN ["python3", "manage.py", "collectstatic"]
CMD ["python3", "manage.py", "runserver", "0.0.0.0:8000"]
......@@ -5,4 +5,4 @@ from donor.models import JadwalDonor
@admin.register(JadwalDonor)
class JadwalDonorAdmin(admin.ModelAdmin):
pass
list_filter = ('kecamatan', 'time_start', 'category')
......@@ -18,9 +18,9 @@ class Command(BaseCommand):
start_date = date.today() - timedelta(days=10)
for cur_date in (start_date + timedelta(days=i) for i in range(101)):
for _ in range(random.randint(1, 3)):
JadwalDonor.objects.create_jadwal_donor(
JadwalDonor.objects.create(
kecamatan=random.choice(JadwalDonor.Kecamatan.choices)[0],
location=fake.address(),
location=fake.address()[:30], # Cut to 30 chars
time_start=make_aware(datetime.combine(
cur_date, time(hour=random.randint(8, 12)))),
time_end=make_aware(datetime.combine(
......
from django.db import models
from django.core.exceptions import ValidationError
from django.utils.timezone import localtime
class JadwalDonor(models.Model):
......@@ -37,4 +38,6 @@ class JadwalDonor(models.Model):
return super().save(*args, **kwargs)
def __str__(self):
return f"{self.location}, {self.time_start.date()} ({self.time_start.time()} - {self.time_end.time()})"
time_start = localtime(self.time_start)
time_end = localtime(self.time_end)
return f"{self.location}, {time_start.date()} ({time_start.time()} - {time_end.time()})"
......@@ -7,8 +7,8 @@ from django.core.exceptions import ValidationError
class JadwalDonorTest(TestCase):
def test_create_jadwal_donor_success(self):
time_start = '2020-03-02T07:08:00+00:00'
time_end = '2020-03-02T10:08:00+00:00'
time_start = '2020-03-02T07:08:00+07:00'
time_end = '2020-03-02T10:08:00+07:00'
jadwal_donor = JadwalDonor.objects.create(
kecamatan="Beji", location='Fasilkom', time_start=datetime.fromisoformat(time_start),
time_end=datetime.fromisoformat(time_end), quota=150, category=JadwalDonor.Category.PUBLIC
......@@ -16,8 +16,8 @@ class JadwalDonorTest(TestCase):
self.assertEqual(str(jadwal_donor), f"Fasilkom, 2020-03-02 (07:08:00 - 10:08:00)")
def test_create_jadwal_donor_start_greater_than_end_fail(self):
time_start = '2020-03-02T10:08:00+00:00'
time_end = '2020-03-02T07:08:00+00:00'
time_start = '2020-03-02T10:08:00+07:00'
time_end = '2020-03-02T07:08:00+07:00'
with self.assertRaisesMessage(ValidationError, "time_start should be less than time_end"):
JadwalDonor.objects.create(
kecamatan="Beji", location='Pacil', time_start=datetime.fromisoformat(time_start),
......
......@@ -7,9 +7,9 @@ from donor.models import JadwalDonor
class JadwalDonorTests(APITestCase):
def test_get_jadwal_donor_sorted_by_time_start(self):
time_start_1 = '2020-03-02T06:00:00Z'
time_start_2 = '2020-03-02T07:00:00Z'
time_end = '2020-03-02T10:00:00Z'
time_start_1 = '2020-03-02T06:00:00+07:00'
time_start_2 = '2020-03-02T07:00:00+07:00'
time_end = '2020-03-02T10:00:00+07:00'
# insert time_start_2 first to make sure it is not sorted by id
JadwalDonor.objects.create(
kecamatan="Beji", location="Depok Baru", time_start=time_start_2,
......@@ -44,10 +44,10 @@ class JadwalDonorTests(APITestCase):
)
def test_get_jadwal_donor_filtered_by_date(self):
time_start_1 = '2020-03-02T06:00:00Z'
time_start_2 = '2020-03-03T07:00:00Z'
time_end_1 = '2020-03-02T10:00:00Z'
time_end_2 = '2020-03-03T10:00:00Z'
time_start_1 = '2020-03-02T06:00:00+07:00'
time_start_2 = '2020-03-03T07:00:00+07:00'
time_end_1 = '2020-03-02T10:00:00+07:00'
time_end_2 = '2020-03-03T10:00:00+07:00'
JadwalDonor.objects.create(
kecamatan="Beji", location="Depok", time_start=time_start_1,
time_end=time_end_1, quota=150, category=JadwalDonor.Category.PUBLIC
......
#!/usr/bin/env python
#!/usr/bin/env python3
"""Django's command-line utility for administrative tasks."""
import os
import sys
def main():
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'dblood.settings')
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'dblood.settings.staging')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
......
......@@ -2,7 +2,8 @@
-r requirements.txt
coverage==5.0.3
django-extensions==2.2.8
factory_boy==2.12.0
flake8-django==0.0.4
psycopg2-binary==2.8.4
Faker==4.0.1
\ No newline at end of file
Faker==4.0.1
# Install common packages between env
-r requirements.txt
gunicorn==20.0.4
psycopg2==2.8.4
......@@ -5,6 +5,4 @@ dj-database-url==0.5.0
Django==3.0.3
django-anymail==7.0.0
djangorestframework==3.11.0
gunicorn==20.0.4
django-extensions==2.2.8
django-cors-headers==3.2.1
\ No newline at end of file
django-cors-headers==3.2.1
# This docker-compose.yml reflect api service in staging settings
version: '3'
services:
api:
build:
context: ./backend
dockerfile: dev.Dockerfile # Staging Container Image
restart: always
# environment:
# - SECRET_KEY=another_totally_secret_random_bytes_no_one_can_touch # There's a fallback
# - DATABASE_URL=postgres://mantan:aab@db/dblood # You can try with postgres too
ports:
- "8080:8000"
networks:
- default
- internal
# db:
# image: postgres:12
# environment:
# - POSTGRES_USER=mantan
# - POSTGRES_PASSWORD=aab
# - POSTGRES_DB=dblood
# volumes:
# - .data/postgresql:/var/lib/postgresql
# networks:
# - internal
networks:
default:
internal:
internal: true
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