Compare commits

...

6 Commits

Author SHA1 Message Date
2e11715194 Build release -vs- local sources
This commit closes #5

./docker/build.sh              # build local sources
./docker/build.sh -r 0.1.0 -p  # build known release
2024-08-25 18:05:41 +02:00
7d96d7a52a global repo/module name
This commit closes #4
2024-08-25 16:13:36 +02:00
b0629205c1 Update README
This commit closes #2

- Add list of similar projects
- Build locally
- Docker builder container
2024-08-22 23:00:06 +02:00
beaf379300 Incorrect MIME type for *.js files
This commit closes #3

Caddy server relies on Alpine's file type MIME discovery,
which as of Alpine v3.20 is broken:

$ file --mime-type -b simple.js
> text/plain
2024-08-22 21:05:46 +02:00
a33e3e1fb9 Update README.md 2024-08-18 16:37:15 +02:00
ab64efe5dd Update README.md 2024-08-18 16:35:17 +02:00
9 changed files with 194 additions and 76 deletions

View File

@ -1,9 +1,18 @@
# caddy reload --config /etc/caddy/Caddyfile
{
order gitea before file_server
}
:3003
gitea {
token {$GITEA_ACCESS_TOKEN} # Settings > Applications > Generate Token
server {$GITEA_HOST} # https://yourgitea.yourdomain.com
token {$GITEA_ACCESS_TOKEN} # Settings > Applications > Generate Token
server {$GITEA_HOST} # https://yourgitea.yourdomain.com
domain {$PAGES_DOMAIN} # pages.yourdomain.com
}
@js {
path *.js
}
header @js {
Content-Type text/javascript # https://gitea.djmil.dev/djmil/gitea-pages/issues/3
}

View File

@ -1,16 +0,0 @@
FROM caddy:2.8.4-builder-alpine AS builder
COPY pkg/gitea/* /module/gitea-pages/pkg/gitea/
COPY gitea-pages.go go.mod go.sum /module/gitea-pages/
RUN xcaddy build \
--with gitea.djmil.dev/goland/gitea-pages \
--replace gitea.djmil.dev/goland/gitea-pages=/module/gitea-pages \
--replace gitea.djmil.dev/goland/gitea-pages/pkg/gitea=/module/gitea-pages/pkg/gitea
FROM caddy:2.8.4
COPY --from=builder /usr/bin/caddy /usr/bin/caddy
COPY Caddyfile /etc/caddy/Caddyfile
EXPOSE 3003/tcp

View File

@ -1,6 +1,6 @@
# gitea-pages
Fork of the [caddy-gitea](https://github.com/42wim/caddy-gitea) project: [Gitea](https://gitea.io) plugin for [Caddy v2](https://github.com/caddyserver/caddy).
Fork of the [caddy-gitea](https://github.com/42wim/caddy-gitea) project: [Gitea](https://gitea.io) plugin for [Caddy v2](https://github.com/caddyserver/caddy). List of [alternatives](https://docs.gitea.com/awesome#web-hosting).
The project aims to have Github Pages in Gitea. For doing so it relies on a wildcard CNAME DNS entry to the gitea host.
@ -8,16 +8,16 @@ For now markdown files (with `.md` extension) will also be automatically generat
<!-- TOC -->
- [caddy-gitea](#caddy-gitea)
- [Getting started](#getting-started)
- [Caddy config](#caddy-config)
- [DNS config](#dns-config)
- [Gitea config](#gitea-config)
- [gitea-pages repo](#gitea-pages-repo)
- [any repo with configurable allowed branch/tag/commits](#any-repo-with-configurable-allowed-branchtagcommits)
- [any repo with all branches/tags/commits exposed](#any-repo-with-all-branchestagscommits-exposed)
- [Building caddy](#building-caddy)
- [Integration & deployment](#Integration with Gitea)
- [Getting started](#getting-started)
- [Caddy config](#caddy-config)
- [DNS config](#dns-config)
- [Gitea config](#gitea-config)
- [gitea-pages repo](#gitea-pages-repo)
- [any repo with configurable allowed branch/tag/commits](#any-repo-with-configurable-allowed-branchtagcommits)
- [any repo with all branches/tags/commits exposed](#any-repo-with-all-branchestagscommits-exposed)
- [Building caddy with plugin](#building-caddy)
- [Build locally](#build-with-locally-cloned-plugin-sources)
- [Integration with Gitea](#integration-with-gitea)
<!-- /TOC -->
@ -112,15 +112,38 @@ e.g. we'll use the `yourrepo` repo in the `yourorg` org and there is a `file.htm
## Building caddy
As this is a 3rd party plugin you'll need to build caddy (or use the binaries).
To build with this plugin you'll need to have go1.19 installed.
To build with this plugin you'll need to have `Golang v1.19` installed. Basic idea:
```bash
go install github.com/caddyserver/xcaddy/cmd/xcaddy@latest #this will install xcaddy in ~/go/bin
# 1 install xcaddy in ~/go/bin
go install github.com/caddyserver/xcaddy/cmd/xcaddy@latest
# 2 build caddy binary with the latest plugin version
xcaddy build \
--with gitea.djmil.dev/goland/gitea-pages \
--replace gitea.djmil.dev/goland/gitea-pages=/module/gitea-pages \
--replace gitea.djmil.dev/goland/gitea-pages/pkg/gitea=/module/gitea-pages/pkg/gitea
--with gitea.djmil.dev/djmil/gitea-pages
```
### Build with locally cloned plugin sources
Also Docker builder image can be used to build caddy alongside locally cloned git repo of a plugin:
```Dockerfile
FROM caddy:2.8.4-builder-alpine AS builder
COPY gitea-pages.go go.mod go.sum /module/gitea-pages/
COPY pkg/gitea/* /module/gitea-pages/pkg/gitea/
RUN xcaddy build \
--with gitea.djmil.dev/djmil/gitea-pages \
--replace gitea.djmil.dev/djmil/gitea-pages=/module/gitea-pages \
--replace gitea.djmil.dev/djmil/gitea-pages/pkg/gitea=/module/gitea-pages/pkg/gitea
FROM caddy:2.8.4
COPY --from=builder /usr/bin/caddy /usr/bin/caddy
COPY Caddyfile /etc/caddy/Caddyfile
EXPOSE 3003/tcp
```
## Integration with Gitea
@ -180,4 +203,4 @@ services:
- gitea
ports:
- "3003:3003"
```
```

98
docker/build.sh Executable file
View File

@ -0,0 +1,98 @@
#!/bin/bash
set -e
usage="$(basename "$0") [--release=<version>] [--publish] [-h]
Compile Caddy server with gitea-pages plugin inside docker container. Buy
default local sources will be used for build.
You can also compile known release. The given release tag will be fetched from
the project git repo at https://gitea.djmil.dev/djmil/gitea-pages.
Optionally, the script can be used to publish resulting docker image to the
https://hub.docker.com/repository/docker/djmil/gitea-pages.
Params for the short options version shall be separated by space. For the long
options - equal sign shall be used. Example:
--release=0.1.0
-r 0.0.1
Where:
-l | --local
Build local sources. Default behaviour.
-r | --release <version>
A major.minor.patch tag of the known release to build.
-p | --publish
Publish resulting image to the docker hub. Typically shall be used
together with --release option.
-h | --help
Show this message and exit.
"
R="\033[0;31m" # RED
G="\033[0;32m" # GREEN
Y="\033[0;33m" # YELLOW
B="\033[1;34m" # BLUE
NC="\033[0;0m" # NO COLOR
###############################################################################
# Parse long and short options, source: https://stackoverflow.com/a/28466267
# Defaults
tag='local'
publish=false
die() { echo "$*" >&2; exit 2; } # complain to STDERR and exit with error
needs_arg() { if [ -z "$OPTARG" ]; then die "No arg for --$OPT option"; fi; }
while getopts r:lph-: OPT; do # allow -a, -b with arg, -c, and -- "with arg"
# support long options: https://stackoverflow.com/a/28466267/519360
if [ "$OPT" = "-" ]; then # long option: reformulate OPT and OPTARG
OPT="${OPTARG%%=*}" # extract long option name
OPTARG="${OPTARG#"$OPT"}" # extract long option argument (may be empty)
OPTARG="${OPTARG#=}" # if long option argument, remove assigning `=`
fi
case "$OPT" in
l | local ) tag='local' ;;
r | release ) needs_arg; tag="$OPTARG" ;;
p | publish ) publish=true ;;
h | help ) echo "$usage" >&2; exit 0 ;;
\? ) exit 2 ;; # bad short option (error reported via getopts)
* ) die "Illegal option --$OPT" ;; # bad long option
esac
done
shift $((OPTIND-1)) # remove parsed options and args from $@ list
###############################################################################
if [ $tag = 'local' ]; then
echo -e "${Y} -->> Local dev-mode build: compile local sources${NC}";
docker build \
--file docker/local.dockerfile \
--tag djmil/gitea-pages:local \
.
exit 0
fi
echo -e "${Y} -->> Building release ${B}'$tag'${NC}";
docker build \
--file docker/release.dockerfile \
--build-arg RELEASE=$tag \
--tag djmil/gitea-pages:$tag \
.
if $publish; then
echo -e "${Y} -->> Publishing to the dockerhub";
docker login --username djmil #--password-stdin
docker push djmil/gitea-pages:$tag
fi

24
docker/local.dockerfile Normal file
View File

@ -0,0 +1,24 @@
FROM caddy:2.8.4-builder-alpine AS builder
#
# mount root of the build context as /module/gitea-pages
# inside the container and run `xcaddy build` command
# also use cache to speed up subsequent builds
#
# $> go env GOCACHE <<-- Golang build cache
# $> go env GOMODCACHE <<-- Goland module download cache
#
RUN --mount=type=bind,target=/module/gitea-pages \
--mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg/mod \
xcaddy build \
--with gitea.djmil.dev/djmil/gitea-pages \
--replace gitea.djmil.dev/djmil/gitea-pages=/module/gitea-pages \
--replace gitea.djmil.dev/djmil/gitea-pages/pkg/gitea=/module/gitea-pages/pkg/gitea
FROM caddy:2.8.4
COPY --from=builder /usr/bin/caddy /usr/bin/caddy
COPY Caddyfile /etc/caddy/Caddyfile
EXPOSE 3003/tcp

19
docker/release.dockerfile Normal file
View File

@ -0,0 +1,19 @@
FROM caddy:2.8.4-builder-alpine AS builder
ARG RELEASE
#
# $> go env GOCACHE <<-- Golang build cache
# $> go env GOMODCACHE <<-- Goland module download cache
#
RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg/mod \
xcaddy build \
--with gitea.djmil.dev/djmil/gitea-pages@$RELEASE
FROM caddy:2.8.4
COPY --from=builder /usr/bin/caddy /usr/bin/caddy
COPY Caddyfile /etc/caddy/Caddyfile
EXPOSE 3003/tcp

View File

@ -5,7 +5,7 @@ import (
"net/http"
"strings"
"gitea.djmil.dev/goland/gitea-pages/pkg/gitea"
"gitea.djmil.dev/djmil/gitea-pages/pkg/gitea"
"github.com/caddyserver/caddy/v2"
"github.com/caddyserver/caddy/v2/caddyconfig/caddyfile"
"github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile"

2
go.mod
View File

@ -1,4 +1,4 @@
module gitea-pages
module gitea.djmil.dev/djmil/gitea-pages
go 1.19

View File

@ -1,39 +0,0 @@
#!/bin/bash
set -e
usage="$(basename "$0") [-h] [-t RELEASE_VERSION ]
The script compiles Caddy server with GiteaPages plugin, and publishes the resulting image
to the https://hub.docker.com/u/djmil
Where:
-t RELEASE_VERSION
A major.minor.patch tag for the image being publisdhed.
"
tag=''
while getopts ht: flag
do
case "${flag}" in
t) tag=${OPTARG};;
h) echo "$usage"; exit 0;;
*) echo "$usage" >&2; exit 1;;
esac
done
if [ ! "$tag" ]; then
echo 'Missing: -t RELEASE_VERSION' >&2
exit 1
fi
echo "Tag: $tag";
docker build --tag djmil/gitea-pages:$tag .
#git tag
#git push tag
docker login --username djmil #--password-stdin
docker push djmil/gitea-pages:$tag