Skip to content

Commit

Permalink
use redis store for tracking favicon downloads
Browse files Browse the repository at this point in the history
  • Loading branch information
ilude committed May 9, 2024
1 parent 724327c commit 549088d
Show file tree
Hide file tree
Showing 16 changed files with 444 additions and 464 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ app/static/assets

notebooks/data/

cache/
app/.working/
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"python.analysis.extraPaths": [
"./app",
"./app/services",
"./app",
"./app"
]
}
158 changes: 79 additions & 79 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,16 @@ ARG PYTHON_VERSION=3.12-slim-bookworm
FROM python:${PYTHON_VERSION} as base
LABEL maintainer="Mike Glenn <[email protected]>"

ARG PUID=${PUID:-1000}
ARG PGID=${PGID:-1000}

ARG USER=anvil
ARG TZ=America/New_York
ENV USER=${USER}
ENV TZ=${TZ}

ARG PROJECT_NAME
ENV PROJECT_NAME=${PROJECT_NAME}

ARG PROJECT_PATH=/app
ENV PROJECT_PATH=${PROJECT_PATH}

ARG ONBOARD_PORT=9830
ENV ONBOARD_PORT=${ONBOARD_PORT}

ENV PYTHON_DEPS_PATH=/dependencies
ENV PYTHONPATH="${PYTHONPATH}:${PYTHON_DEPS_PATH}"
ENV PYTHONUNBUFFERED=TRUE

ENV LANGUAGE=en_US.UTF-8
ENV LANG=en_US.UTF-8
ENV LC_ALL=C.UTF-8
ENV DEBIAN_FRONTEND=noninteractive
ENV DEBCONF_NONINTERACTIVE_SEEN=true

ENV HOME=/home/${USER}
ARG TERM_SHELL=zsh
ENV TERM_SHELL=${TERM_SHELL}

RUN apt-get update && apt-get install -y --no-install-recommends \
bash \
ca-certificates \
Expand All @@ -52,6 +31,68 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
apt-get autoclean -y && \
rm -rf /var/lib/apt/lists/*

RUN sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && locale-gen
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8


##############################
# Begin build
##############################
FROM base as build

RUN apt-get update && apt-get install -y --no-install-recommends \
binutils \
build-essential \
pkg-config gfortran \
cmake \
coreutils \
extra-cmake-modules \
findutils \
git \
openssl \
openssh-client \
sqlite3 \
libsqlite3-dev && \
apt-get autoremove -fy && \
apt-get clean && \
apt-get autoclean -y && \
rm -rf /var/lib/apt/lists/*

COPY requirements.txt requirements.txt
RUN pip3 install --upgrade pip && \
pip3 install --upgrade setuptools && \
pip3 install --upgrade wheel && \
mkdir -p ${PYTHON_DEPS_PATH} && \
pip3 install --no-cache-dir --target=${PYTHON_DEPS_PATH} -r requirements.txt && \
rm -rf requirements.txt


##############################
# Begin user_base
##############################
FROM base as user_base

ARG PUID=${PUID:-1000}
ARG PGID=${PGID:-1000}

ARG USER=anvil
ENV USER=${USER}

ARG PROJECT_NAME
ENV PROJECT_NAME=${PROJECT_NAME}

ARG PROJECT_PATH=/app
ENV PROJECT_PATH=${PROJECT_PATH}

ARG ONBOARD_PORT=9830
ENV ONBOARD_PORT=${ONBOARD_PORT}

ENV HOME=/home/${USER}
ARG TERM_SHELL=zsh
ENV TERM_SHELL=${TERM_SHELL}

RUN sed -i 's/UID_MAX .*/UID_MAX 100000/' /etc/login.defs && \
groupadd --gid ${PGID} ${USER} && \
useradd --uid ${PUID} --gid ${PGID} -s /bin/${TERM_SHELL} -m ${USER} && \
Expand All @@ -78,13 +119,13 @@ if [ "$(id -u)" = "0" ]; then
groupmod -o -g ${PGID:-1000} ${USER}
usermod -o -u ${PUID:-1000} ${USER}

# get gid of docker socket file
SOCK_DOCKER_GID=`stat -c %g /var/run/docker.sock`
groupmod -o -g "$SOCK_DOCKER_GID" ${USER}
chown ${USER}:${USER} /var/run/docker.sock

# Add call to gosu to drop from root user to jenkins user
# Add call to gosu to drop from root user
# when running original entrypoint
set -- gosu ${USER} "$@"
else
sudo chown -R ${USER}:${USER} /var/run/docker.sock
fi

echo "Running: $@"
Expand All @@ -94,66 +135,29 @@ EOF
WORKDIR $PROJECT_PATH
ENTRYPOINT [ "/usr/local/bin/docker-entrypoint.sh" ]


##############################
# Begin build
##############################
FROM base as build

RUN apt-get update && apt-get install -y --no-install-recommends \
binutils \
build-essential \
pkg-config gfortran \
cmake \
coreutils \
extra-cmake-modules \
findutils \
git \
openssl \
openssh-client \
sqlite3 \
libsqlite3-dev && \
apt-get autoremove -fy && \
apt-get clean && \
apt-get autoclean -y && \
rm -rf /var/lib/apt/lists/*

COPY requirements.txt requirements.txt
RUN pip3 install --upgrade pip && \
pip3 install --upgrade setuptools && \
pip3 install --upgrade wheel && \
mkdir -p ${PYTHON_DEPS_PATH} && \
chown -R ${USER}:${USER} ${PROJECT_PATH} ${PYTHON_DEPS_PATH} && \
pip3 install --no-cache-dir --target=${PYTHON_DEPS_PATH} -r requirements.txt && \
rm -rf requirements.txt


##############################
# Begin production
##############################
FROM base as production
FROM user_base as production

COPY --from=build --chown=${USER}:${USER} ${PYTHON_DEPS_PATH} ${PYTHON_DEPS_PATH}
COPY --from=build --chown=${USER}:${USER} ${PYTHON_DEPS_PATH} ${PYTHON_DEPS_PATH}
COPY --chown=${USER}:${USER} app ${PROJECT_PATH}

ENV FLASK_ENV=production

RUN mkdir /cache && \
chown -R ${USER}:${USER} /cache && \
mkdir -p /app/static/icons && \
mkdir -p /app/static/assets &&\
RUN mkdir -p /app/static/icons && \
mkdir -p /app/static/assets && \
chown -R ${USER}:${USER} /app/static

HEALTHCHECK --interval=10s --timeout=3s --start-period=40s \
CMD wget --no-verbose --tries=1 --spider --no-check-certificate http://localhost:$ONBOARD_PORT/api/healthcheck || exit 1


CMD [ "python3", "app.py" ]

##############################
# Begin jupyter-devcontainer
# Begin jupyter-builder
##############################
FROM build as jupyter-devcontainer
FROM build as jupyter-builder

RUN apt-get update && apt-get install -y --no-install-recommends \
graphviz \
Expand All @@ -173,11 +177,6 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
apt-get autoclean -y && \
rm -rf /var/lib/apt/lists/*

##############################
# Begin jupyter-builder
##############################
FROM jupyter-devcontainer as jupyter-builder

RUN pip3 install --no-cache-dir --target=${PYTHON_DEPS_PATH} docutils h5py ipykernel ipython jupyter jupyterhub notebook numpy nltk pyyaml pylint scikit-learn scipy==1.11.0 watermark
RUN pip3 install --no-cache-dir --target=${PYTHON_DEPS_PATH} --no-deps --prefer-binary matplotlib seaborn plotly graphviz imutils keras
RUN pip3 install --no-cache-dir --target=${PYTHON_DEPS_PATH} --prefer-binary pandas-datareader bottleneck scipy duckdb sqlalchemy pyautogui requests_cache statsmodels
Expand All @@ -186,16 +185,15 @@ RUN pip3 install --no-cache-dir --target=${PYTHON_DEPS_PATH} --prefer-binary pan
##############################
# Begin devcontainer
##############################
FROM jupyter-devcontainer as devcontainer

COPY --from=jupyter-builder --chown=${USER}:${USER} ${PYTHON_DEPS_PATH} ${PYTHON_DEPS_PATH}
FROM user_base as devcontainer

RUN apt-get update && apt-get install -y --no-install-recommends \
ansible \
bash-completion \
dnsutils \
exa \
iproute2 \
iputils-ping \
jq \
openssh-client \
ripgrep \
Expand All @@ -219,8 +217,10 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
USER ${USER}

COPY .devcontainer .devcontainer
RUN LC_ALL=C.UTF-8 ansible-playbook --inventory 127.0.0.1 --connection=local .devcontainer/ansible/requirements.yml && \
LC_ALL=C.UTF-8 ansible-playbook --inventory 127.0.0.1 --connection=local .devcontainer/ansible/install-docker.yml

RUN ansible-playbook --inventory 127.0.0.1 --connection=local .devcontainer/ansible/requirements.yml && \
ansible-playbook --inventory 127.0.0.1 --connection=local .devcontainer/ansible/install-docker.yml

COPY --from=jupyter-builder --chown=${USER}:${USER} ${PYTHON_DEPS_PATH} ${PYTHON_DEPS_PATH}

# https://code.visualstudio.com/remote/advancedcontainers/start-processes#_adding-startup-commands-to-the-docker-image-instead
CMD [ "sleep", "infinity" ]
10 changes: 9 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
.SUFFIXES:
SITE_PACKAGES := $(shell pip show pip | grep '^Location' | cut -d' ' -f2-)
SITE_PACKAGES := $(shell pip show pip | grep '^Location' | cut -d' ' -f2-)

# read and include .devcontainer/.env exporting all variables
ifneq (,$(wildcard .devcontainer/.env))
include .devcontainer/.env
export
endif

ifneq (,$(wildcard .env))
include .env
export
endif


.PHONY: run reqs ansible
run: $(SITE_PACKAGES)
@clear
-@killall python3 3>&1 1>/dev/null 2>&3 || true
python3 app/app.py

reqs: $(SITE_PACKAGES)
Expand Down
3 changes: 1 addition & 2 deletions app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,10 @@

@app.context_processor
def inject_current_date():
favicon_finder = models.layout.FaviconFinder()
return {
'today_date': datetime.now(),
'site_title': os.environ.get('ONBOARD_SITE_TITLE', 'OnBoard'),
'favicon_exists': favicon_finder.favicon_exists,
'favicon_path': layout.favicon_path,
}


Expand Down
37 changes: 23 additions & 14 deletions app/defaults/layout.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ tabs:
- name: Frigate
link: https://frigate.traefikturkey.icu/
- name: Proxmox - ilude.com
link: https://pve.ilude.com:8006/
link: 'https://pve.ilude.com:8006/#v1:0:=qemu%2F101:4:::::::'
- name: Proxmox - traefikturkey.icu
link: https://pve-patriot.ilude.com:8006/
link: 'https://pve-patriot.ilude.com:8006/#v1:0:=qemu%2F101:4:::::::'
- name: Vaultwarden
link: https://vaultwarden.ilude.com/

Expand Down Expand Up @@ -118,13 +118,17 @@ tabs:
type: "feed"
link: "https://www.battleswarmblog.com/"
feed_url: "https://www.battleswarmblog.com/?feed=rss2"
- name: "Cafe Hayek"
- name: "Slashdot"
type: "feed"
link: "https://cafehayek.com/"
feed_url: "https://cafehayek.com/feed"
filters:
strip:
- summary: '^Tweet\s*\.{0,3}|\…\s+'
summary_enabled: False
link: "https://slashdot.org/"
feed_url: "https://rss.slashdot.org/Slashdot/slashdotMain"
- name: "Phoronix"
type: "feed"
summary_enabled: False
link: "https://www.phoronix.com"
feed_url: "https://www.phoronix.com/rss.php"


- column:
widgets:
Expand All @@ -135,16 +139,14 @@ tabs:
- name: "Krebs on Security"
type: "feed"
summary_enabled: False
display_limit: 12
link: "https://krebsonsecurity.com/"
feed_url: "https://krebsonsecurity.com/feed/"
- name: "Slashdot"
- name: "Linux Hint"
type: "feed"
summary_enabled: False
display_limit: 12
link: "https://slashdot.org/"
feed_url: "https://rss.slashdot.org/Slashdot/slashdotMain"

link: "https://linuxhint.com/"
feed_url: "https://linuxhint.com/feed/"

- column:
widgets:
- name: "Instapundit"
Expand All @@ -161,6 +163,13 @@ tabs:
type: "feed"
link: "https://twitchy.com/"
feed_url: "https://twitchy.com/feed"
- name: "Cafe Hayek"
type: "feed"
link: "https://cafehayek.com/"
feed_url: "https://cafehayek.com/feed"
filters:
strip:
- summary: '^Tweet\s*\.{0,3}|\…\s+'

- tab: "Tech"
columns:
Expand Down
1 change: 0 additions & 1 deletion app/defaults/processed_domains.json

This file was deleted.

Loading

0 comments on commit 549088d

Please sign in to comment.