Skip to content

Commit

Permalink
docker: create new container with cronjob tar-ing result daily
Browse files Browse the repository at this point in the history
  • Loading branch information
nikromen committed Dec 15, 2023
1 parent 7e08d7d commit 3f13b1d
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 19 deletions.
16 changes: 16 additions & 0 deletions docker-compose.prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ services:
website:
build:
context: docker/production
dockerfile: Dockerfile.website
image: quay.io/jkadlcik/log-detective
hostname: log-detective
stdin_open: true
Expand All @@ -11,6 +12,21 @@ services:
- 8080:8080
volumes:
- persistent:/persistent:z
env_file:
- "files/.env"

cron:
build:
context: docker/production
dockerfile: Dockerfile.cron
image: quay.io/log-detective/cron
hostname: cron
stdin_open: true
tty: true
volumes:
- persistent:/persistent:z
env_file:
- "files/env"

volumes:
persistent:
20 changes: 18 additions & 2 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,25 @@ services:
volumes:
- .:/opt/log-detective-website:z
- persistent:/persistent
env_file:
- "files/env"
environment:
- ENV=devel
- FEEDBACK_DIR=/persistent/results
- PYTHONPATH=/opt/log-detective-website

cron:
build:
context: .
dockerfile: docker/cron/Dockerfile
hostname: cron
command: "crond -f"
stdin_open: true
tty: true
volumes:
- persistent:/persistent
env_file:
- "files/env"

# The frontend container is only a quality of life for development.
# For production, we will simply compile the ClojureScript into JavaScript
# and deploy it.
Expand All @@ -40,9 +55,10 @@ services:
- 3333:3333
volumes:
- .:/opt/log-detective-website:z
env_file:
- "files/env"
environment:
- ENV=devel
- FEEDBACK_DIR=/persistent/results

volumes:
persistent:
14 changes: 14 additions & 0 deletions docker/cron/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM registry.fedoraproject.org/fedora:38
MAINTAINER [email protected]

RUN dnf -y update
RUN dnf -y install cronie tar

RUN touch /var/log/cron.log

COPY files/cron/tar_persistent.sh /bin/tar_persistent
RUN chmod +x /bin/tar_persistent

COPY files/cron/crontab_daily /etc/cron.d/crontab_daily
RUN chmod +x /etc/cron.d/crontab_daily
RUN crontab /etc/cron.d/crontab_daily
28 changes: 28 additions & 0 deletions docker/production/Dockerfile.cron
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
FROM registry.fedoraproject.org/fedora:38
MAINTAINER [email protected]

ENV ENV=production

RUN dnf -y update
RUN dnf -y install git

RUN git clone https://github.com/fedora-copr/log-detective-website.git /src

FROM registry.fedoraproject.org/fedora:38
MAINTAINER [email protected]

ENV ENV=production

RUN dnf -y update
RUN dnf -y install cronie tar

RUN touch /var/log/cron.log

COPY --from=0 /src/files/cron/tar_persistent.sh /bin/tar_persistent
RUN chmod +x /bin/tar_persistent

COPY --from=0 /src/files/cron/crontab_daily /etc/cron.d/crontab_daily
RUN chmod +x /etc/cron.d/crontab_daily
RUN crontab /etc/cron.d/crontab_daily

CMD ["crond", "-f"]
Original file line number Diff line number Diff line change
@@ -1,24 +1,11 @@
FROM registry.fedoraproject.org/fedora:38
MAINTAINER [email protected]

ENV FEEDBACK_DIR=/persistent/results
ENV ENV=production

RUN dnf -y update && \
# Base packages
dnf -y install htop \
make \
wget \
net-tools \
iputils \
vim \
mlocate \
jq \
fpaste \
git \
sudo \
python3-ipdb \
findutils \
dnf -y install git \
# Frontend
&& dnf -y install \
npm \
Expand All @@ -36,7 +23,6 @@ RUN npx shadow-cljs release app
FROM registry.fedoraproject.org/fedora:38
MAINTAINER [email protected]

ENV FEEDBACK_DIR=/persistent/results
ENV ENV=production

RUN dnf -y install python3-fastapi \
Expand All @@ -47,13 +33,25 @@ RUN dnf -y install python3-fastapi \
python3-koji \
python3-copr \
koji \
htop \
btop \
make \
wget \
net-tools \
iputils \
vim \
mlocate \
jq \
fpaste \
git \
python3-ipdb \
findutils \
&& dnf clean all \
&& mkdir -p /src/{frontend,backend}

COPY --from=0 /src/frontend/public /src/frontend/public
COPY --from=0 /src/backend /src/backend

# According to the documentation, gunicorn is a valid production server
# https://www.uvicorn.org/deployment/
WORKDIR /src/backend
ENV PYTHONPATH="${PYTHONPATH}:/src"

Expand Down
5 changes: 5 additions & 0 deletions files/cron/crontab_daily
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin

# run every day at 1:05AM
5 1 * * * root tar_persistent >> /var/log/cron.log 2>&1
7 changes: 7 additions & 0 deletions files/cron/tar_persistent.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/sh

# archive results tar_persistent.sh and remove the old ones
FILE_NAME=data-$(date +%s).tar.gz
tar -czvf $STORAGE_DIR/new-$FILE_NAME -C $FEEDBACK_DIR . && \
rm -f $STORAGE_DIR/data-*.tar.gz && \
mv $STORAGE_DIR/new-$FILE_NAME $STORAGE_DIR/$FILE_NAME
2 changes: 2 additions & 0 deletions files/env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
STORAGE_DIR=/persistent
FEEDBACK_DIR=/persistent/results

0 comments on commit 3f13b1d

Please sign in to comment.