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

Atualiza toda a aplicação para ser acomodada a instância de produção #28

Merged
merged 10 commits into from
Nov 2, 2021
Merged
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
25 changes: 25 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
**/__pycache__
**/.classpath
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/bin
**/charts
**/docker-compose*
**/compose*
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
README.md
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Others
data/
env.dev
env.prod
*.vscode

# Byte-compiled / optimized / DLL files
__pycache__/
Expand Down
32 changes: 0 additions & 32 deletions Dockerfile

This file was deleted.

33 changes: 20 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ pip install .
_Set the environment variables_

```shell
export $(cat dev.ini | xargs)
export $(cat .env.dev | xargs)
```

_Create a PostgreSQL database named "spf"_

```shell
# Through a Docker container with a PostgreSQL database
docker exec --user postgres -it scielo-postgres-1 psql -c 'create database spf;'
docker exec --user postgres -it scl_postgres_1 psql -c 'create database spf;'

# Or through psql
psql --user postgres;
Expand Down Expand Up @@ -108,22 +108,29 @@ python ../manage.py compilemessages

```shell
# Ensure you are in the project root directory. Executing `ls .` will list the following files/directories:
dev.env
app
docker-compose.yml
docker-entrypoint.sh
Dockerfile
LICENSE
prod.env
nginx
README.md
requirements.txt
setup.py
spf

# Build image
docker-compose -f docker-compose.yml build
# Create a .env.prod file (and add to it the necessary environment variables)
touch .env.prod

# Create and start a container with the image built
docker-compose up
# Build image and start the services
docker-compose -f docker-compose.yml up -d --build

# Migrate data
docker-compose -f docker-compose.yml exec web python manage.py migrate --noinput

# Collect static files
docker-compose -f docker-compose.yml exec web python manage.py collectstatic --no-input --clear

# Load default groups
docker-compose -f docker-compose.yml exec web python manage.py loaddata group

# Load example users
docker-compose -f docker-compose.yml exec web python manage.py loaddata user

# Make sure PostgreSQL and MongoDB databases are in the same network as the spf application
```
Expand Down
47 changes: 47 additions & 0 deletions app/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
FROM python:3.9.6-alpine

WORKDIR /usr/src/app

ENV PYTHONDONTWRITEBYTECODE 1

ENV PYTHONUNBUFFERED 1

RUN apk update \
&& apk add postgresql-dev \
gcc \
git \
build-base \
py3-lxml \
python3-dev \
musl-dev \
libxml2-dev \
libxslt-dev \
libffi-dev

RUN pip install --upgrade pip

COPY ./requirements.txt .

RUN pip install -r requirements.txt

RUN mkdir -p /home/app

RUN addgroup -S app && adduser -S app -G app

ENV HOME=/home/app

ENV APP_HOME=/home/app/web

RUN mkdir ${APP_HOME}

RUN mkdir ${APP_HOME}/staticfiles

RUN mkdir ${APP_HOME}/mediafiles

WORKDIR ${APP_HOME}

COPY . ${APP_HOME}

RUN chown -R app:app ${APP_HOME}

USER app
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
65 changes: 65 additions & 0 deletions app/core/static/js/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
function createMessage(msg){
divAlert = document.createElement('div');
divAlert.classList.add('alert', 'alert-danger', 'alert-dismissible', 'fade', 'show', 'is-no-rounded', 'm-0', 'p-2');
divAlert.setAttribute('role', 'alert');

divContainer = document.createElement('div');
divContainer.classList.add('container', 'text-center');
divContainer.innerHTML = msg;

btnClose = document.createElement('button');
btnClose.type = 'button';
btnClose.classList.add('btn-close', 'btn-sm', 'm-1', 'p-2');
btnClose.setAttribute('data-bs-dismiss', 'alert');
btnClose.setAttribute('aria-label', 'Close');

divContainer.appendChild(btnClose);
divAlert.appendChild(divContainer);

return divAlert;
}

function ingressPackageDownloadToggleSpinner(){
var btnSearchPackage = document.getElementById('btnSearchPackage');
var divSpinner = document.getElementById('searchPackageLoading');
if (divSpinner.style.display == "none") {
divSpinner.style.display = 'block';
btnSearchPackage.setAttribute('disabled', 'disabled');
} else {
divSpinner.style.display = 'none';
btnSearchPackage.removeAttribute('disabled');
}
}

function ingressPackageDownloadCreateTable(data){
tableBody = document.getElementById('resultSearchPackagesTableBody')

for (k in data['doc_pkgs']){
els = data['doc_pkgs'][k];
row = tableBody.insertRow(-1);

aResult = document.createElement('a')
aResult.text = els['name'];
aResult.href = els['uri'];
aResult.classList.add('link');

tdUri = row.insertCell(-1);
tdUri.appendChild(aResult);

tdCreated = row.insertCell(-1);
tdCreated.innerHTML = els['created'];

tdUpdated = row.insertCell(-1);
tdUpdated.innerHTML = els['updated'];
}

if (data['doc_pkgs'].length > 0) {
document.getElementById('resultSearchPackages').style.display = 'block';
} else {
var divBaseMessages = document.getElementById('baseMessages');
for (k in data['errors']){
element_message = createMessage(data['errors'][k]);
divBaseMessages.append(element_message);
}
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
90 changes: 90 additions & 0 deletions app/core/templates/ingress/package_download.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
{% extends "base.html" %}
{% load i18n %}
{% load spf_extras %}

{% block title %}
SciELO Publishing Framework - {% trans 'Search package' %}
{% endblock %}

{% block content %}
<h1 class="h4 pt-5">{% trans 'Search package' %}</h1>

<div class="row my-3">
<div class="col-sm-5 mb-3">
<div class="card my-3">
<div class="card-header">
{% trans 'Search package' %}
</div>
<div class="card-body">
<form class="bg-white form-user" method="GET" action="{% url 'ingress_package_download' %}">
{% csrf_token %}
<div class="mb-3">
<label for="pid" class="form-label">{% trans 'Document identifier' %}</label>
<input required type="text" name="pid" autofocus id="pid" class="form-control" placeholder="{% trans 'Enter a document identifier' %}" value="{{ pid }}">
</div>
<button id="btnSearchPackage" type="submit" class="btn btn-primary">{% trans 'Search' %}</button>
</form>
</div>
</div>
<div id='searchPackageLoading' style="display: none;" role="status">
<div class="spinner-border text-primary">
<span class="sr-only">{% trans 'Loading' %}...</span>
</div>
<span class="text-primary px-1 fw-bold">{% trans 'Collecting resources' %}</span>
</div>
<div class="alert alert-danger" id="resultErrors" style="display: none;"></div>
</div>

<div id="resultSearchPackages" class="table-responsive" style="display: none;">
<h2 class="h4">{% trans 'Results for document' %} <strong>{{ pid }}</strong></h2>
<table class="table table-bordered" id="table">
<thead>
<tr>
<th>{% trans 'Package' %}</th>
<th>{% trans 'Creation date' %}</th>
<th>{% trans 'Update date' %}</th>
</tr>
</thead>
<tbody id="resultSearchPackagesTableBody">
</tbody>
</table>
</div>

</div>
<script type="text/javascript">
var xhr;
var checkStatus = '{{ check_status }}';
var intervals = {}

function update(){
xhr = $.ajax({
url: '/task/update_status/?task_id={{ task_id }}',
type: 'GET',
success: function(result) {
divSpinner = document.createElement('div');
divSpinner.classList.add('spinner-border');
divSpinner.setAttribute('role', 'status');

spanLoading = document.createElement('span');
spanLoading.classList.add('sr-only');
spanLoading.text = "{% trans 'Loading' %}...";

divSpinner.appendChild(spanLoading);

$('user-package-download-results').add(divSpinner);

if (result.data && 'doc_pkgs' in result.data) {
clearInterval(intervals[0]);
ingressPackageDownloadCreateTable(result.data);
ingressPackageDownloadToggleSpinner();
}
}
});
}

if (checkStatus) {
intervals[0] = setInterval(update, 200);
ingressPackageDownloadToggleSpinner();
}
</script>
{% endblock %}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
0 spf/manage.py → app/manage.py
100755 → 100644
File renamed without changes.
15 changes: 8 additions & 7 deletions requirements.txt → app/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
asgiref==3.4.1
#asgiref==3.4.1
celery==5.1.2
confusable-homoglyphs==3.2.0
Django==3.2.5
#confusable-homoglyphs==3.2.0
Django==3.2.6
django-celery-results==2.2.0
psycopg2-binary==2.9
pytz==2021.1
psycopg2-binary==2.9.1
#pytz==2021.1
python-dateutil==2.8.2
sqlparse==0.4.1
#sqlparse==0.4.1
lxml==4.6.3
minio==7.1.0
gunicorn==20.1.0
-e git+https://github.com/scieloorg/opac_schema.git#egg=opac_schema
-e git+https://github.com/scieloorg/dsm.git#egg=dsm
-e git+https://github.com/scieloorg/scielo_v3_manager.git#egg=scielo_v3_manager
-e git+https://github.com/scieloorg/scielo_v3_manager.git#egg=scielo_v3_manager
1 change: 1 addition & 0 deletions setup.py → app/setup.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
'confusable-homoglyphs',
'Django',
'django-celery-results',
'gunicorn',
'pytz',
'python-dateutil',
'sqlparse',
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading