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

Cron updates and default admin for values in init admin #16

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ RUN echo "**** install NearBeach Latest ****" && \
pip install NearBeach

RUN echo "**** copy over the crontab configuration ****"
COPY crontab /etc/crontabs/root
COPY --chown=nearbeach:nearbeach crontab /etc/crontabs/nearbeach

RUN echo "**** setup of working directory ****"
WORKDIR /oceansuite
RUN chown nearbeach:nearbeach /oceansuite
#USER nearbeach

USER nearbeach

RUN echo "**** copy everything into the destination ****"
COPY --chown=nearbeach:nearbeach . .
Expand Down
6 changes: 6 additions & 0 deletions Dockerfile.base
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ RUN echo "**** install build packages ****" && \
tini \
tk-dev \
zlib-dev
dcron \
libcap

RUN echo "**** allow nearbeach user to run cron ****" && \
chown nearbeach:nearbeach /usr/sbin/crond && \
setcap cap_setgid=ep /usr/sbin/crond

ARG TARGET_BRANCH=main
# Copy the requirements.txt file
Expand Down
6 changes: 3 additions & 3 deletions extra/management/commands/initadmin.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
class Command(BaseCommand):
def handle(self, *args, **options):
if User.objects.count() == 0:
username = os.getenv("ADMIN_USERNAME")
email = os.getenv("ADMIN_EMAIL")
username = os.getenv("ADMIN_USERNAME", "admin")
email = os.getenv("ADMIN_EMAIL", "admin@localhost")
password = self.generate_initial_password()
print('Creating account for %s (%s)' % (username, email))
admin = User.objects.create_superuser(email=email, username=username, password=password)
admin.is_active = True
admin.is_admin = True
admin.save()

# from https://docs.python.org/3/library/secrets.html#recipes-and-best-practices
def generate_initial_password(self):
alpha = string.ascii_letters + string.digits
Expand Down
4 changes: 3 additions & 1 deletion oceansuite/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@
}


# CRONTAB_TIMESTR="0 0 * * *"

# Password validation
# https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators

Expand Down Expand Up @@ -171,7 +173,7 @@
STATIC_URL = '/static/'
else:
STATIC_URL = F"https://cdn.nearbeach.org/{VERSION}/"

MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR,'media/')

Expand Down
7 changes: 5 additions & 2 deletions setup_db_and_run_server.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ python manage.py migrate
python manage.py initadmin
echo "**** DB setup complete ****"

echo "**** Updating Crontab ****"
python manage.py updatecrontab

echo "**** Starting Cron Services ****"
crond
crond -b -l 8

echo "**** running NearBeach ****"
python manage.py runserver 0.0.0.0:8000
python manage.py runserver 0.0.0.0:8000