Compare commits

..
13 Commits
8 changed files with 74 additions and 18 deletions
+1
View File
@@ -14,3 +14,4 @@ devenv.local.nix
# pre-commit
.pre-commit-config.yaml
/result
+48
View File
@@ -0,0 +1,48 @@
# Frajul's F-Droid Repo
This contains the code for the deployment of my own F-Droid.
## Deployment overview
The deployment works via `docker`.
The container is defined in `flake.nix`.
Every `30 min`, it runs the script `hosting/update.sh`, which git-pulls this repo to update its scripts, then executes `scripts/update-apks.sh` and if any apks have been added or removed, it runs `fdroid update` to re-build the repo, which is located in the `fdroid` directory.
This repo is served by a `caddy` server from the container on port `:8080`.
### How to build and deploy
To build the container run:
```sh
nix build .#container
```
To load the resulting `gitlab.julian-mutter.de/julian/fdroid-frajul:latest` container into the local docker daemon, run:
```sh
docker load < result
```
For building and deploying the container to the remote registry, simply run the following command, which is provided by the `flake.nix` dev shell:
```sh
deploy
```
## Container configuration
### Environment variables
- *SOPS_AGE_KEY*
The files `fdroid/config.yml` and `fdroid/keystore.p12` are encrypted with `sops`.
The update script automatically decrypts them on the first start of the container.
For this to work the environment variable `SOPS_AGE_KEY` must be set to the age key used for encrypting.
This key can be generated by running `age-keygen -o key.txt`.
### External volumes
- */apks*
The update script downloads new apk versions into the `/apks` directory.
The apks in there are synced on each update run to the `/src/code/fdroid/repo` directory, where they are served from.
Therefore, the `/apks` directory is the perfect place to mount an external volume to persist all apks and avoid re-downloading on container restart.
This also allows manually placing apks to be served into this directory.
## Apk update scripts
To automatically pull new versions of an apk, create a bash script in the `scripts/apk-update-scripts` directory.
This script should be idempotent and download all available apk versions with differring file names into the `/apks` directory, if not already present.
All these scripts are automatically run regularly by `scripts/update-apks.sh`.
+10 -4
View File
@@ -46,19 +46,20 @@
tag = "latest";
contents = with pkgs; [
coreutils
bashInteractive
caddy
dockerTools.fakeNss # Provides fake /etc/passwd for basic user emulation
dockerTools.usrBinEnv
dockerTools.binSh
dockerTools.caCertificates
coreutils
bashInteractive
caddy
fdroidserver
jq
curl
sops
git
rsync
busybox
];
config = {
@@ -67,6 +68,9 @@
ExposedPorts = {
"8080/tcp" = {};
};
Env = [
"PATH=/bin:${pkgs.jdk21_headless}/bin"
];
};
maxLayers = 10;
};
@@ -74,6 +78,8 @@
# nix build .#container
# docker load < result
packages.${system}.container = dockerImage;
# deploy
devShells.${system}.default = pkgs.mkShell {
packages = [
deploy-script
+2 -3
View File
@@ -5,9 +5,8 @@
# 2. Redirect without trailing slash to ensure correct routing
redir /fdroid/repo /fdroid/repo/ 302
# 3. Strip '/fdroid/repo' from the URL and serve the underlying files
handle_path /fdroid/repo/* {
root * /repo/fdroid/repo
file_server browse
root * /src/code/fdroid/repo
file_server
}
}
-4
View File
@@ -1,4 +0,0 @@
#!/usr/bin/env sh
docker build . -t gitlab.julian-mutter.de/julian/fdroid-frajul:latest
docker push gitlab.julian-mutter.de/julian/fdroid-frajul:latest
+1
View File
@@ -51,6 +51,7 @@ fi
# Run fdroid update if needed
if [ "$NEED_FDROID_UPDATE" = true ]; then
echo "Running fdroid update..."
cd fdroid
fdroid update -c
fdroid update
echo "Done"
+1 -1
View File
@@ -14,7 +14,7 @@ APK_DIR="/apks"
# ==========================================
# SETUP & API CALL
# ==========================================
mkdir -p "$FDROID_REPO_DIR"
mkdir -p "$APK_DIR"
API_URL="${GITEA_URL}/api/v1/repos/${REPO_OWNER}/${REPO_NAME}/releases"
+11 -6
View File
@@ -16,13 +16,18 @@ done
# Sync all apks from the mounted dir to dest
SOURCE="/apks/"
DEST="/src/code/fdroid/repo/"
OUTPUT=$(rsync -avi --include="*.apk" --exclude="*" --delete "$SOURCE" "$DEST")
# Check if the output contains the specific tags for new files (>f) or deleted files (*deleting)
if echo "$OUTPUT" | grep -q -E '^>f|^\*deleting'; then
echo "Changes detected! Files were copied or deleted."
exit 10
else
HASH_BEFORE=$(stat -c "%A %h %U %G %s %n" "$DEST"* | sha256sum)
echo "Syncing apks in directory $DEST with $SOURCE..."
rsync -rv --include="*.apk" --exclude="*" --delete "$SOURCE" "$DEST"
HASH_AFTER=$(stat -c "%A %h %U %G %s %n" "$DEST"* | sha256sum)
if [ "$HASH_BEFORE" == "$HASH_AFTER" ]; then
echo "No APKs were added or removed. Skipping F-Droid update."
exit 0
else
echo "Changes detected! Files were copied or deleted."
exit 10
fi