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 cd307a8 commit d0631d6
Show file tree
Hide file tree
Showing 10 changed files with 130 additions and 23 deletions.
14 changes: 13 additions & 1 deletion docker-compose.prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ services:
website:
build:
context: docker/production
image: quay.io/jkadlcik/log-detective
dockerfile: Dockerfile.website
image: quay.io/log-detective/website
hostname: log-detective
stdin_open: true
tty: true
Expand All @@ -12,5 +13,16 @@ services:
volumes:
- persistent:/persistent:z

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

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 copr-devel@lists.fedorahosted.org

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
32 changes: 32 additions & 0 deletions docker/production/Dockerfile.cron
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
FROM registry.fedoraproject.org/fedora:38
MAINTAINER copr-devel@lists.fedorahosted.org

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 copr-devel@lists.fedorahosted.org

ENV ENV=production

# TODO: how to get envs from env file in openshift?
ENV STORAGE_DIR=/persistent
ENV FEEDBACK_DIR=/persistent/results

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,15 @@
FROM registry.fedoraproject.org/fedora:38
MAINTAINER copr-devel@lists.fedorahosted.org

ENV FEEDBACK_DIR=/persistent/results
ENV ENV=production

# TODO: how to get envs from env file in openshift?
ENV STORAGE_DIR=/persistent
ENV FEEDBACK_DIR=/persistent/results

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,9 +27,12 @@ RUN npx shadow-cljs release app
FROM registry.fedoraproject.org/fedora:38
MAINTAINER copr-devel@lists.fedorahosted.org

ENV FEEDBACK_DIR=/persistent/results
ENV ENV=production

# TODO: how to get envs from env file in openshift?
ENV STORAGE_DIR=/persistent
ENV FEEDBACK_DIR=/persistent/results

RUN dnf -y install python3-fastapi \
python3-uvicorn \
python3-gunicorn \
Expand All @@ -47,13 +41,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
4 changes: 2 additions & 2 deletions openshift/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ docker-compose -f docker-compose.prod.yaml build --no-cache
```

Push the image to quay.io
[quay.io/jkadlcik/log-detective][quay-repo]:
[quay.io/log-detective][quay-organization]:

```
docker-compose -f docker-compose.prod.yaml push
Expand Down Expand Up @@ -77,7 +77,7 @@ oc logs -f deploy/log-detective-website
oc rsh deploy/log-detective-website
```

[quay-repo]: https://quay.io/repository/jkadlcik/log-detective
[quay-repo]: https://quay.io/repository/log-detective/website
[group1]: https://accounts.fedoraproject.org/group/communishift/
[group2]: https://accounts.fedoraproject.org/group/communishift-log-detective/

Expand Down
15 changes: 14 additions & 1 deletion openshift/log-detective.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ spec:
claimName: persistent
containers:
- name: log-detective-website
image: quay.io/jkadlcik/log-detective:latest
image: quay.io/log-detective/website:latest
imagePullPolicy: Always
ports:
- containerPort: 8080
Expand All @@ -33,6 +33,19 @@ spec:
limits:
memory: "800Mi"
cpu: "1"
- name: log-detective-cron
image: quay.io/log-detective/cron:latest
imagePullPolicy: Always
volumeMounts:
- name: persistent
mountPath: /persistent
resources:
requests:
memory: "400Mi"
cpu: "50m"
limits:
memory: "800Mi"
cpu: "1"
replicas: 1
strategy:
type: Recreate
Expand Down

0 comments on commit d0631d6

Please sign in to comment.