Skip to content

Commit 22490f5

Browse files
committed
add Docker container and helper script
1 parent c6a3adb commit 22490f5

File tree

4 files changed

+140
-0
lines changed

4 files changed

+140
-0
lines changed

dev/Dockerfile

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# https://docs.docker.com/engine/reference/builder/
2+
3+
# https://hub.docker.com/_/debian
4+
FROM debian:bookworm-slim
5+
6+
# Configure apt not to prompt during docker build
7+
ARG DEBIAN_FRONTEND=noninteractive
8+
9+
# Configure apt to avoid installing recommended and suggested packages
10+
RUN apt-config dump \
11+
| grep -E '^APT::Install-(Recommends|Suggests)' \
12+
| sed -e's/1/0/' \
13+
| tee /etc/apt/apt.conf.d/99no-recommends-no-suggests
14+
15+
# Resynchronize the package index and install packages
16+
# https://docs.docker.com/build/building/best-practices/#apt-get
17+
RUN apt-get update && apt-get install -y \
18+
curl \
19+
git \
20+
gir1.2-pango-1.0 \
21+
libnginx-mod-http-fancyindex \
22+
nginx-light \
23+
python3-gi-cairo \
24+
tree \
25+
&& rm -rf /var/lib/apt/lists/*
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
server {
2+
listen 80;
3+
server_name localhost;
4+
root /srv/licensebuttons/www;
5+
location /i {
6+
fancyindex on;
7+
fancyindex_header /header.html;
8+
fancyindex_footer /footer-i.html;
9+
fancyindex_exact_size off;
10+
}
11+
location / {
12+
fancyindex on;
13+
fancyindex_header /header.html;
14+
fancyindex_footer /footer.html;
15+
fancyindex_exact_size off;
16+
}
17+
}
18+
# vim: ft=nginx

dev/genicons.sh

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Run Python code tools (isort, black, flake8)
4+
#
5+
#### SETUP ####################################################################
6+
7+
set -o errexit
8+
set -o errtrace
9+
set -o nounset
10+
11+
# shellcheck disable=SC2154
12+
trap '_es=${?};
13+
printf "${0}: line ${LINENO}: \"${BASH_COMMAND}\"";
14+
printf " exited with a status of ${_es}\n";
15+
exit ${_es}' ERR
16+
17+
DIR_REPO="$(cd -P -- "${0%/*}/.." && pwd -P)"
18+
# https://en.wikipedia.org/wiki/ANSI_escape_code
19+
E0="$(printf "\e[0m")" # reset
20+
E30="$(printf "\e[30m")" # black foreground
21+
E31="$(printf "\e[31m")" # red foreground
22+
E107="$(printf "\e[107m")" # bright white background
23+
24+
#### FUNCTIONS ################################################################
25+
26+
check_docker() {
27+
local _msg
28+
if ! docker compose exec web true 2>/dev/null; then
29+
_msg='The app container/services is not avaialable.'
30+
_msg="${_msg}\n First run \`docker compose up\`."
31+
error_exit "${_msg}"
32+
fi
33+
}
34+
35+
error_exit() {
36+
# Echo error message and exit with error
37+
echo -e "${E31}ERROR:${E0} ${*}" 1>&2
38+
exit 1
39+
}
40+
41+
icon_stats() {
42+
local _count _size
43+
print_header 'Icons stats'
44+
echo '/srv/licensebuttons/www/i'
45+
_count=$(docker compose exec web find /srv/licensebuttons/www/i -type f \
46+
| wc -l | tr -d '[:space:]')
47+
_size=$(docker compose exec web du -sh /srv/licensebuttons/www/i \
48+
| awk '{print $1}')
49+
printf ' %11s %5s\n' 'File count:' "${_count}"
50+
printf ' %11s %5s\n' 'Size:' "${_size}"
51+
echo
52+
}
53+
54+
print_header() {
55+
# Print 80 character wide black on white heading with time
56+
printf "${E30}${E107}# %-69s$(date '+%T') ${E0}\n" "${@}"
57+
}
58+
59+
#### MAIN #####################################################################
60+
61+
cd "${DIR_REPO}"
62+
63+
check_docker
64+
65+
icon_stats
66+
67+
print_header 'Generate icons in Docker container'
68+
docker compose exec web \
69+
/usr/bin/python3 /srv/licensebuttons/scripts/genicons.py
70+
echo 'done.'
71+
echo
72+
73+
icon_stats

docker-compose.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# https://docs.docker.com/compose/compose-file/
2+
3+
services:
4+
web:
5+
build:
6+
dockerfile: dev/Dockerfile
7+
command: sh -c "
8+
echo 'Starting static webserver at http://127.0.0.1:8080/'
9+
&& nginx -g 'daemon off;'
10+
"
11+
init: true
12+
ports:
13+
- '8080:80'
14+
restart: on-failure
15+
volumes:
16+
- .:/srv/licensebuttons
17+
- ./dev/etc-nginx-sites-available-default:/etc/nginx/sites-available/default:ro
18+
- ./www/cc-icons.ttf:/root/.fonts/cc-icons.ttf:ro
19+
- licbuttons-www-i:/srv/licensebuttons/www/i
20+
working_dir: /srv/licensebuttons
21+
22+
volumes:
23+
licbuttons-www-i:
24+
name: licbuttons-www-i

0 commit comments

Comments
 (0)