Add the ability to test the website locally

That serve the website to http://127.0.0.1:8080/

Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
This commit is contained in:
Denis 'GNUtoo' Carikli 2022-11-23 01:39:34 +01:00
parent 44aa09777d
commit 58fc2a673d
Signed by: GNUtoo
GPG Key ID: 5F5DFCC14177E263
4 changed files with 76 additions and 1 deletions

1
.gitignore vendored
View File

@ -1,4 +1,5 @@
/untitled/
/id_oauth2_bearer
/index.html
/lighttpd.conf
/website.tar.gz

View File

@ -35,12 +35,27 @@ build:
./build.sh
help:
@printf "%s\n\t%s\n\t%s\n\t%s\n" \
@printf "%s\n\t%s\n\t%s\n\t%s\n\t%s\n" \
"Available commands:" \
"help # Print this help" \
"test # run lighttpd on localhost:8080" \
"upload # Upload the website to https://$(DOMAIN)" \
"website.tar.gz # Create a tarball of the website"
test: website.tar.gz
guix shell \
--container \
--network \
--emulate-fhs \
bash \
coreutils \
gzip \
lighttpd \
sed \
tar \
-- \
./serve.sh website.tar.gz
upload: website.tar.gz
curl \
--oauth2-bearer `cat id_oauth2_bearer` \
@ -54,6 +69,8 @@ index.html: index.html.tmpl
website.tar.gz: build index.html
sed 's/DOMAIN/$(DOMAIN)/' index.html.tmpl > index.html
tar \
--exclude-vcs \
--exclude-vcs-ignores \
--format=gnu \
--mtime='1970-01-01 00:00Z' \
--owner=0 --group=0 --numeric-owner \

16
lighttpd.conf.tmpl Normal file
View File

@ -0,0 +1,16 @@
server.bind = "localhost"
server.port = 8080
server.document-root = "TMPDIR"
dir-listing.activate = "enable"
index-file.names = ( "index.html" )
mimetype.assign = (
".html" => "text/html",
".txt" => "text/plain",
".css" => "text/css",
".js" => "application/x-javascript",
".jpg" => "image/jpeg",
".jpeg" => "image/jpeg",
".gif" => "image/gif",
".png" => "image/png",
"" => "application/octet-stream"
)

41
serve.sh Executable file
View File

@ -0,0 +1,41 @@
#!/bin/sh
# Copyright (C) 2022 Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
set -e
usage()
{
echo "$0 <path/to/tarball>"
exit 1
}
if [ $# -ne 1 ] ; then
usage
fi
basedir="$(dirname $(realpath $0))"
tarball="$1"
tmpdir="$(mktemp -d)"
tar xf "${tarball}" -C "${tmpdir}"
sed "s#TMPDIR#${tmpdir}#g" \
"${basedir}/lighttpd.conf.tmpl" > \
"${basedir}/lighttpd.conf"
lighttpd -f lighttpd.conf -D