Skip to content

Commit

Permalink
InitialSwitch (#77)
Browse files Browse the repository at this point in the history
Co-authored-by: Tom <TommyE123@users.noreply.github.com>
Co-authored-by: Eric Nemchik <eric@nemchik.com>
  • Loading branch information
TommyE123 and nemchik authored Apr 30, 2023
1 parent a979093 commit 6107e3d
Show file tree
Hide file tree
Showing 22 changed files with 130 additions and 97 deletions.
2 changes: 1 addition & 1 deletion .checkov.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
quiet: true
skip-check:
- CKV_DOCKER_3
- CKV_DOCKER_3 # lsio images run containers as non-root by default
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@
.gitattributes export-ignore
.gitignore export-ignore
.gitkeep export-ignore

# Force root folder
/root/** text eol=lf
3 changes: 2 additions & 1 deletion .hadolint.yaml → .hadolint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
## Hadolint config file ##
##########################
ignored:
- DL3018
- DL3013 # Pin versions in pip.
- DL3018 # Pin versions in apk add.
43 changes: 19 additions & 24 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,37 +1,32 @@
# Set the base image
FROM ghcr.io/linuxserver/baseimage-alpine:3.17

# Set the timezone
ARG TZ=Europe/London
ENV TZ=$TZ

# Set the maintainer
LABEL maintainer="GhostWriters"

# Copy files from host to container
COPY root /

# Install required packages and application dependencies
RUN apk update && apk add --no-cache py3-pip tzdata && \
ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && \
echo $TZ > /etc/timezone && \
pip3 install --no-cache-dir packt==1.7.0

# Update UID and GID of existing user "abc" to match PUID and PGID if supplied
ARG PUID=1000
ARG PGID=1000
RUN if [ "$PUID" -ne 1000 ] || [ "$PGID" -ne 1000 ]; then \
usermod -u $PUID abc && \
groupmod -g $PGID abc; \
fi

# Set user "abc" as default user
USER abc
RUN \
echo "**** install runtime packages ****" && \
apk add --no-cache \
python3 && \
echo "**** install app ****" && \
python3 -m ensurepip && \
pip3 install -U --no-cache-dir \
pip \
wheel \
packt==1.8.0 && \
echo "**** cleanup ****" && \
rm -rf \
/tmp/* \
"$HOME/.cache"

# Add a health check command to ensure the container is running correctly
HEALTHCHECK --interval=1m \
--timeout=3s \
CMD ps -ef | grep cron || exit 1

# Specify the entrypoint
ENTRYPOINT ["/opt/docker-entrypoint.sh"]
# copy local files
COPY root/ /

# ports and volumes
VOLUME /config
Empty file added root/etc/crontabs/abc
Empty file.
3 changes: 2 additions & 1 deletion root/etc/crontabs/root
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
0 8 * * * packt-cli -gd -c /config/configFile.cfg 2>&1 | tee /config/logFile.log
# min hour day month weekday command
0 8 * * * packt-cli -gd -c /config/configFile.cfg 2>&1 | tee /config/logFile.log
Empty file.
Empty file.
38 changes: 38 additions & 0 deletions root/etc/s6-overlay/s6-rc.d/init-crontabs-config/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/with-contenv bash
# shellcheck shell=bash

# make folders
mkdir -p \
/config/crontabs

## root
# if crontabs do not exist in config
if [[ ! -f /config/crontabs/root ]]; then
# copy crontab from system
if crontab -l -u root; then
crontab -l -u root >/config/crontabs/root
fi

# if crontabs still do not exist in config (were not copied from system)
# copy crontab from included defaults (using -n, do not overwrite an existing file)
cp -n /etc/crontabs/root /config/crontabs/
fi
# set permissions and import user crontabs
lsiown root:root /config/crontabs/root
crontab -u root /config/crontabs/root

## abc
# if crontabs do not exist in config
if [[ ! -f /config/crontabs/abc ]]; then
# copy crontab from system
if crontab -l -u abc; then
crontab -l -u abc >/config/crontabs/abc
fi

# if crontabs still do not exist in config (were not copied from system)
# copy crontab from included defaults (using -n, do not overwrite an existing file)
cp -n /etc/crontabs/abc /config/crontabs/
fi
# set permissions and import user crontabs
lsiown abc:abc /config/crontabs/abc
crontab -u abc /config/crontabs/abc
1 change: 1 addition & 0 deletions root/etc/s6-overlay/s6-rc.d/init-crontabs-config/type
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
oneshot
1 change: 1 addition & 0 deletions root/etc/s6-overlay/s6-rc.d/init-crontabs-config/up
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/etc/s6-overlay/s6-rc.d/init-crontabs-config/run
Empty file.
56 changes: 56 additions & 0 deletions root/etc/s6-overlay/s6-rc.d/init-packt-cli-config/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/with-contenv bash
# shellcheck shell=bash

CFG="/config/configFile.cfg"

# Downloads and copies a new configfile template if one is not present in the config dir.
if [[ ! -f "$CFG" ]]; then
echo "No config file, providing sample"
wget -O "$CFG" https://gitlab.com/packt-cli/packt-cli/-/raw/master/configFileTemplate.cfg
fi

# If environment arguments have been provided, switch the values in the config to these.
if [[ -n "$PACKT_EMAIL" ]]; then
echo "ENV PACKT_EMAIL provided"
sed -i "s/email=.*/email=\"$PACKT_EMAIL\"/" "$CFG"
else
echo "ENV PACKT_EMAIL not set"
fi

if [[ -n "$PACKT_PASSWORD" ]]; then
echo "ENV PACKT_PASSWORD provided"
sed -i "s/password=.*/password=\"$PACKT_PASSWORD\"/" "$CFG"
else
echo "ENV PACKT_PASSWORD not set"
fi

if [[ -n "$PACKT_DOWNLOAD_FORMATS" ]]; then
echo "ENV PACKT_DOWNLOAD_FORMATS provided as \"$PACKT_DOWNLOAD_FORMATS\""
sed -i "s/download_formats:.*/download_formats:\ \"$PACKT_DOWNLOAD_FORMATS\"/" "$CFG"
else
echo "ENV PACKT_DOWNLOAD_FORMATS not set"
fi

if [[ -n "$PACKT_DOWNLOAD_BOOK_TITLES" ]]; then
echo "ENV PACKT_DOWNLOAD_BOOK_TITLES provided as \"$PACKT_DOWNLOAD_BOOK_TITLES\""
sed -i "s/download_book_titles:.*/download_book_titles:\ \"$PACKT_DOWNLOAD_BOOK_TITLES\"/" "$CFG"
else
echo "ENV PACKT_DOWNLOAD_BOOK_TITLES not set"
sed -i "s/download_book_titles:.*/download_book_titles:/" "$CFG"
fi

if [[ -n "$PACKT_ANTICAPTCHA_KEY" ]]; then
echo "ENV PACKT_ANTICAPTCHA_Key provided"
sed -i "s/key:.*/key:\ \"$PACKT_ANTICAPTCHA_KEY\"/" "$CFG"
else
echo "ENV PACKT_ANTICAPTCHA_KEY not set"
fi

echo "Replacing path with /data"
sed -i "s@download_folder_path:.*@download_folder_path:\ \\/data@" "$CFG"

echo "Set logfile path to /data"
sed -i "s@ebook_extra_info_log_file_path:.*@ebook_extra_info_log_file_path:\ \\/data\\/eBookMetadata.log@" "$CFG"

# set permissions
lsiown -R abc:abc /config
1 change: 1 addition & 0 deletions root/etc/s6-overlay/s6-rc.d/init-packt-cli-config/type
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
oneshot
1 change: 1 addition & 0 deletions root/etc/s6-overlay/s6-rc.d/init-packt-cli-config/up
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/etc/s6-overlay/s6-rc.d/init-packt-cli-config/run
Empty file.
4 changes: 4 additions & 0 deletions root/etc/s6-overlay/s6-rc.d/svc-cron/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/with-contenv bash
# shellcheck shell=bash

exec /usr/sbin/crond -f -S -l 5
1 change: 1 addition & 0 deletions root/etc/s6-overlay/s6-rc.d/svc-cron/type
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
longrun
Empty file.
Empty file.
Empty file.
70 changes: 0 additions & 70 deletions root/opt/docker-entrypoint.sh

This file was deleted.

0 comments on commit 6107e3d

Please sign in to comment.