Compare commits
13
Commits
52c10d7223
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0684aaa1c6 | ||
|
|
1fb8acf316 | ||
|
|
97a8597c00 | ||
|
|
8cf3945f1c | ||
|
|
e7f70de19a | ||
|
|
6cab77cf22 | ||
|
|
24e54a1da0 | ||
|
|
ed961c58dd | ||
|
|
0d80be4715 | ||
|
|
f63c603ddb | ||
|
|
352e32adbc | ||
|
|
4a421a675c | ||
|
|
ad4a2bfb82 |
@@ -14,3 +14,4 @@ devenv.local.nix
|
|||||||
|
|
||||||
# pre-commit
|
# pre-commit
|
||||||
.pre-commit-config.yaml
|
.pre-commit-config.yaml
|
||||||
|
/result
|
||||||
|
|||||||
@@ -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`.
|
||||||
@@ -46,19 +46,20 @@
|
|||||||
tag = "latest";
|
tag = "latest";
|
||||||
|
|
||||||
contents = with pkgs; [
|
contents = with pkgs; [
|
||||||
coreutils
|
|
||||||
bashInteractive
|
|
||||||
caddy
|
|
||||||
dockerTools.fakeNss # Provides fake /etc/passwd for basic user emulation
|
dockerTools.fakeNss # Provides fake /etc/passwd for basic user emulation
|
||||||
dockerTools.usrBinEnv
|
dockerTools.usrBinEnv
|
||||||
dockerTools.binSh
|
dockerTools.binSh
|
||||||
dockerTools.caCertificates
|
dockerTools.caCertificates
|
||||||
|
coreutils
|
||||||
|
bashInteractive
|
||||||
|
caddy
|
||||||
fdroidserver
|
fdroidserver
|
||||||
jq
|
jq
|
||||||
curl
|
curl
|
||||||
sops
|
sops
|
||||||
git
|
git
|
||||||
|
rsync
|
||||||
|
busybox
|
||||||
];
|
];
|
||||||
|
|
||||||
config = {
|
config = {
|
||||||
@@ -67,6 +68,9 @@
|
|||||||
ExposedPorts = {
|
ExposedPorts = {
|
||||||
"8080/tcp" = {};
|
"8080/tcp" = {};
|
||||||
};
|
};
|
||||||
|
Env = [
|
||||||
|
"PATH=/bin:${pkgs.jdk21_headless}/bin"
|
||||||
|
];
|
||||||
};
|
};
|
||||||
maxLayers = 10;
|
maxLayers = 10;
|
||||||
};
|
};
|
||||||
@@ -74,6 +78,8 @@
|
|||||||
# nix build .#container
|
# nix build .#container
|
||||||
# docker load < result
|
# docker load < result
|
||||||
packages.${system}.container = dockerImage;
|
packages.${system}.container = dockerImage;
|
||||||
|
|
||||||
|
# deploy
|
||||||
devShells.${system}.default = pkgs.mkShell {
|
devShells.${system}.default = pkgs.mkShell {
|
||||||
packages = [
|
packages = [
|
||||||
deploy-script
|
deploy-script
|
||||||
|
|||||||
+2
-3
@@ -5,9 +5,8 @@
|
|||||||
# 2. Redirect without trailing slash to ensure correct routing
|
# 2. Redirect without trailing slash to ensure correct routing
|
||||||
redir /fdroid/repo /fdroid/repo/ 302
|
redir /fdroid/repo /fdroid/repo/ 302
|
||||||
|
|
||||||
# 3. Strip '/fdroid/repo' from the URL and serve the underlying files
|
|
||||||
handle_path /fdroid/repo/* {
|
handle_path /fdroid/repo/* {
|
||||||
root * /repo/fdroid/repo
|
root * /src/code/fdroid/repo
|
||||||
file_server browse
|
file_server
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
|
||||||
@@ -51,6 +51,7 @@ fi
|
|||||||
# Run fdroid update if needed
|
# Run fdroid update if needed
|
||||||
if [ "$NEED_FDROID_UPDATE" = true ]; then
|
if [ "$NEED_FDROID_UPDATE" = true ]; then
|
||||||
echo "Running fdroid update..."
|
echo "Running fdroid update..."
|
||||||
|
cd fdroid
|
||||||
fdroid update -c
|
fdroid update -c
|
||||||
fdroid update
|
fdroid update
|
||||||
echo "Done"
|
echo "Done"
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ APK_DIR="/apks"
|
|||||||
# ==========================================
|
# ==========================================
|
||||||
# SETUP & API CALL
|
# SETUP & API CALL
|
||||||
# ==========================================
|
# ==========================================
|
||||||
mkdir -p "$FDROID_REPO_DIR"
|
mkdir -p "$APK_DIR"
|
||||||
|
|
||||||
API_URL="${GITEA_URL}/api/v1/repos/${REPO_OWNER}/${REPO_NAME}/releases"
|
API_URL="${GITEA_URL}/api/v1/repos/${REPO_OWNER}/${REPO_NAME}/releases"
|
||||||
|
|
||||||
|
|||||||
+11
-6
@@ -16,13 +16,18 @@ done
|
|||||||
# Sync all apks from the mounted dir to dest
|
# Sync all apks from the mounted dir to dest
|
||||||
SOURCE="/apks/"
|
SOURCE="/apks/"
|
||||||
DEST="/src/code/fdroid/repo/"
|
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)
|
HASH_BEFORE=$(stat -c "%A %h %U %G %s %n" "$DEST"* | sha256sum)
|
||||||
if echo "$OUTPUT" | grep -q -E '^>f|^\*deleting'; then
|
|
||||||
echo "Changes detected! Files were copied or deleted."
|
echo "Syncing apks in directory $DEST with $SOURCE..."
|
||||||
exit 10
|
rsync -rv --include="*.apk" --exclude="*" --delete "$SOURCE" "$DEST"
|
||||||
else
|
|
||||||
|
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."
|
echo "No APKs were added or removed. Skipping F-Droid update."
|
||||||
exit 0
|
exit 0
|
||||||
|
else
|
||||||
|
echo "Changes detected! Files were copied or deleted."
|
||||||
|
exit 10
|
||||||
fi
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user