Skip to content

Commit 3f43213

Browse files
authored
Change from python webserver to abom-http
1 parent 5b6ebe1 commit 3f43213

File tree

16 files changed

+122
-95
lines changed

16 files changed

+122
-95
lines changed

.github/workflows/test.yaml

+41-3
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,21 @@ jobs:
1010
test-clean-install:
1111
needs: build
1212
runs-on: ubuntu-latest
13+
strategy:
14+
matrix:
15+
mode: ['cache', 'proxy']
1316
steps:
17+
- run: sudo apt-get update && sudo apt-get install -y debconf-utils
18+
- run: echo gitaptly gitaptly/MODE string ${{ matrix.mode }} | sudo debconf-set-selections
19+
- run: curl https://api.github.com/repos/plengauer/abom-http/releases/latest | jq -r '.assets[].browser_download_url' | xargs wget -O ./abomhttp.deb && sudo apt-get install ./abomhttp.deb
1420
- uses: actions/download-artifact@v4
1521
with:
1622
name: package.deb
1723
- run: sudo apt-get -y install ./package.deb
24+
- run: cat /var/lib/gitaptly/dists/stable/main/binary-all/Packages && find /var/lib/gitaptly
25+
- run: ps -ef | grep ncat
26+
- run: time wget http://127.0.0.1:8000/dists/stable/main/binary-all/Packages
27+
- run: time wget http://127.0.0.1:8000/pool/main/plengauer/Utilities/auto_management_1.3.3.deb
1828
- run: echo "deb [arch=all] http://127.0.0.1:8000/ stable main" | sudo tee /etc/apt/sources.list.d/example.list
1929
- run: sudo apt-get update --allow-insecure-repositories
2030
- run: sudo apt-get -y install --allow-unauthenticated auto-management
@@ -23,8 +33,13 @@ jobs:
2333
test-token:
2434
needs: build
2535
runs-on: ubuntu-latest
36+
strategy:
37+
matrix:
38+
mode: ['cache', 'proxy']
2639
steps:
27-
- run: sudo apt-get install -y debconf-utils
40+
- run: sudo apt-get update && sudo apt-get install -y debconf-utils
41+
- run: echo gitaptly gitaptly/MODE string ${{ matrix.mode }} | sudo debconf-set-selections
42+
- run: curl https://api.github.com/repos/plengauer/abom-http/releases/latest | jq -r '.assets[].browser_download_url' | xargs wget -O ./abomhttp.deb && sudo apt-get install ./abomhttp.deb
2843
- run: echo gitaptly gitaptly/GITHUB_API_TOKEN string $GITHUB_API_TOKEN | sudo debconf-set-selections
2944
env:
3045
GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
@@ -40,7 +55,13 @@ jobs:
4055
test-observed:
4156
needs: build
4257
runs-on: ubuntu-latest
58+
strategy:
59+
matrix:
60+
mode: ['cache', 'proxy']
4361
steps:
62+
- run: sudo apt-get update && sudo apt-get install -y debconf-utils
63+
- run: echo gitaptly gitaptly/MODE string ${{ matrix.mode }} | sudo debconf-set-selections
64+
- run: curl https://api.github.com/repos/plengauer/abom-http/releases/latest | jq -r '.assets[].browser_download_url' | xargs wget -O ./abomhttp.deb && sudo apt-get install ./abomhttp.deb
4465
- run: wget -O - https://raw.githubusercontent.com/plengauer/opentelemetry-bash/main/INSTALL.sh | sh -E
4566
- uses: actions/download-artifact@v4
4667
with:
@@ -54,14 +75,31 @@ jobs:
5475
test-upgrade:
5576
needs: build
5677
runs-on: ubuntu-latest
78+
strategy:
79+
matrix:
80+
mode: ['cache', 'proxy']
5781
steps:
58-
- run: wget https://github.com/plengauer/GitAptly/releases/download/v2.0.0/gitaptly_2.0.0.deb
59-
- run: sudo apt-get -y install ./gitaptly_2.0.0.deb
82+
- run: sudo apt-get update && sudo apt-get install -y debconf-utils
83+
- run: echo gitaptly gitaptly/MODE string ${{ matrix.mode }} | sudo debconf-set-selections
84+
- run: curl https://api.github.com/repos/plengauer/abom-http/releases/latest | jq -r '.assets[].browser_download_url' | xargs wget -O ./abomhttp.deb && sudo apt-get install ./abomhttp.deb
85+
# - run: wget https://github.com/plengauer/GitAptly/releases/download/v2.0.0/gitaptly_2.0.0.deb
86+
# - run: sudo apt-get -y install ./gitaptly_2.0.0.deb
87+
# - run: cat /var/lib/gitaptly/dists/stable/main/binary-all/Packages && find /var/lib/gitaptly && ls -la /var/lib/gitaptly/*/main/*/* || true
88+
- run: wget https://github.com/plengauer/GitAptly/releases/download/v3.14.0/gitaptly_3.14.0.deb
89+
- run: sudo apt-get -y install ./gitaptly_3.14.0.deb
90+
- run: cat /var/lib/gitaptly/dists/stable/main/binary-all/Packages && find /var/lib/gitaptly && ls -la /var/lib/gitaptly/*/main/*/* || true
6091
- uses: actions/download-artifact@v4
6192
with:
6293
name: package.deb
6394
- run: sudo apt-get -y install ./package.deb
95+
- run: cat /var/lib/gitaptly/dists/stable/main/binary-all/Packages && find /var/lib/gitaptly && ls -la /var/lib/gitaptly/*/main/*/* || true
6496
- run: echo "deb [arch=all] http://127.0.0.1:8000/ stable main" | sudo tee /etc/apt/sources.list.d/example.list
6597
- run: sudo apt-get update --allow-insecure-repositories
6698
- run: sudo apt-get -y install --allow-unauthenticated auto-management
6799
- run: sudo apt-get -y remove gitaptly
100+
101+
test-all:
102+
needs: [ test-clean-install, test-token, test-observed, test-upgrade ]
103+
runs-on: ubuntu-latest
104+
steps:
105+
- run: exit 0

VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.15.0
1+
4.0.0

package/DEBIAN/control

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: gitaptly
22
Version: __VERSION__
33
Architecture: all
4-
Depends: bash, debconf, coreutils, util-linux, findutils, jq, cron, gzip, dpkg-dev, curl, wget, parallel, python3, python3-pip, python3-venv
4+
Depends: bash, debconf, coreutils, util-linux, findutils, jq, cron, gzip, dpkg-dev, curl, wget, parallel, abom-http
55
Suggests: opentelemetry-shell (>= 4.4.2)
66
Priority: extra
77
Maintainer: Philipp Lengauer <[email protected]>

package/DEBIAN/postinst

+7-12
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ elif [ "$1" != 'configure' ] && [ "$1" != 'reconfigure' ]; then
77
fi
88

99
rm -rf /opt/gitaptly/* || true
10+
rm -rf /var/lib/gitaptly/cgi-bin && sed -i "s/cgi-bin/pool/" /var/lib/gitaptly/dists/stable/main/binary-all/Packages || true # legacy
11+
1012

1113
. /usr/share/debconf/confmodule
1214
db_get gitaptly/PORT
@@ -31,21 +33,14 @@ db_stop
3133

3234
source /opt/gitaptly/env
3335

34-
python3 -m venv /opt/gitaptly/
35-
source /opt/gitaptly/bin/activate
36-
if [ -n "$OTLP_TRACES_ENDPOINT" ] || [ -n "$OTLP_METRICS_ENDPOINT" ] || [ -n "$OTLP_LOGS_ENDPOINT" ]; then
37-
pip3 install opentelemetry-distro opentelemetry-exporter-otlp
38-
pip3 install opentelemetry-instrumentation opentelemetry-instrumentation-system-metrics
39-
opentelemetry-bootstrap -a install
40-
fi
41-
deactivate
42-
36+
touch /var/lib/gitaptly/pool
4337
if [ "$MODE" = "cache" ]; then
44-
find /var/lib/gitaptly/cgi-bin/main/*/*/ -type l -exec rm {} '+' || true
38+
if ! [ -d /var/lib/gitaptly/pool ]; then rm -rf /var/lib/gitaptly/pool && mkdir -p /var/lib/gitaptly/pool; fi
4539
elif [ "$MODE" = "proxy" ]; then
46-
find /var/lib/gitaptly/pool/main/*/*/ -type f -exec rm {} '+' || true
40+
rm -rf /var/lib/gitaptly/pool || true
41+
ln --symbolic /usr/share/gitaptly/serve /var/lib/gitaptly/pool
4742
fi
48-
gitaptly_update
43+
bash /usr/share/gitaptly/update
4944

5045
systemctl daemon-reload
5146
systemctl enable gitaptly

package/etc/cron.d/gitaptly

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
0 * * * * root gitaptly_update
1+
0 * * * * root /usr/share/gitaptly/update
22

package/etc/systemd/system/gitaptly.service

+2-3
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ ExitType=main
66
Restart=always
77
RestartSec=1
88
StartLimitBurst=10
9-
User=root
10-
WorkingDirectory=/opt/gitaptly
11-
ExecStart=gitaptly_run_ftp
9+
User=nobody
10+
ExecStart=/usr/share/gitaptly/run_ftp
1211
[Install]
1312
WantedBy=multi-user.target

package/usr/bin/gitaptly_reset

-2
This file was deleted.

package/usr/bin/gitaptly_serve

-40
This file was deleted.

package/usr/bin/gitaptly_create_release package/usr/share/gitaptly/create_release

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/bin/bash
2+
set -e
23
directory=$1
34

45
cd $directory

package/usr/share/gitaptly/reset

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
set -e
3+
parallel rm -rf ::: /var/lib/gitaptly/dists/stable/Release /var/lib/gitaptly/dists/stable/main/binary-all/Packages.gz /var/lib/gitaptly/dists/stable/main/binary-all/Packages /var/lib/gitaptly/pool/main/*
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
#!/bin/bash -e
22
source /opt/gitaptly/env
3-
source /opt/gitaptly/bin/activate
4-
cmd=(python3 -m http.server --cgi --directory /var/lib/gitaptly $PORT)
53
if [ -n "$OTLP_TRACES_ENDPOINT" ] || [ -n "$OTLP_METRICS_ENDPOINT" ]; then
6-
export OTEL_SERVICE_NAME="GitAptly"
4+
export OTEL_SERVICE_NAME=GitAptly
5+
export OTEL_LOGS_EXPORTER=otlp
76
export OTEL_TRACES_EXPORTER=otlp
87
export OTEL_METRICS_EXPORTER=otlp
98
export OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf
109
export OTEL_EXPORTER_OTLP_TRACES_ENDPOINT="$OTLP_TRACES_ENDPOINT"
11-
export OTEL_EXPORTER_OTLP_METRICS_ENDPOINT="$OTLP_METRICS_ENDPOINT"
1210
export OTEL_EXPORTER_OTLP_TRACES_HEADERS=authorization=$(echo "$OTLP_TRACES_HEADER" | jq -Rr @uri)
11+
export OTEL_EXPORTER_OTLP_METRICS_ENDPOINT="$OTLP_METRICS_ENDPOINT"
1312
export OTEL_EXPORTER_OTLP_METRICS_HEADERS=authorization=$(echo "$OTLP_METRICS_HEADER" | jq -Rr @uri)
14-
cmd=(opentelemetry-instrument "${cmd[@]}")
13+
export OTEL_EXPORTER_OTLP_LOGS_ENDPOINT="$OTLP_LOGS_ENDPOINT"
14+
export OTEL_EXPORTER_OTLP_LOGS_HEADERS=authorization=$(echo "$OTLP_LOGS_HEADER" | jq -Rr @uri)
15+
export OTEL_SHELL_EXPERIMENTAL_OBSERVE_PIPES=TRUE
1516
fi
16-
exec "${cmd[@]}"
17+
abomhttp "$PORT" /var/lib/gitaptly
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1-
#!/bin/bash -e
1+
#!/bin/bash
2+
set -e
23
source /opt/gitaptly/env
34
if [ -n "$GITHUB_API_TOKEN" ]; then
45
auth_header="Authorization: Bearer $GITHUB_API_TOKEN"
56
else
67
auth_header='foo: bar'
78
fi
89
per_page=100
9-
url="https://api.github.com/repos/$1/releases?per_page=$per_page"
10-
curl --no-progress-meter --fail --retry 16 --retry-all-errors --head -H "$auth_header" "$url" \
10+
host=api.github.com
11+
path="/repos/$1/releases?per_page=$per_page"
12+
printf "HEAD $path HTTP/1.1\r\nConnection: close\r\nUser-Agent: gitaptly\r\nHost: $host\r\n$auth_header\r\n\r\n" | ncat --ssl --no-shutdown "$host" 443 \
1113
| grep '^link: ' | cut -d ' ' -f 2- | tr -d ' <>' | tr ',' '\n' \
1214
| grep 'rel="last"' | cut -d ';' -f1 | cut -d '?' -f 2- | tr '&' '\n' \
1315
| grep '^page=' | cut -d = -f 2 \
14-
| xargs seq 1 | xargs parallel -q curl --no-progress-meter --fail --retry 16 --retry-all-errors -H "$auth_header" "$url"\&page={} ::: \
16+
| xargs seq 1 | xargs parallel -q curl --no-progress-meter --fail --retry 16 --retry-all-errors -H "$auth_header" https://"$host""$path"\&page={} ::: \
1517
| jq '.[] | .assets[] | .browser_download_url' -r | (grep '.deb$' || true)

package/usr/share/gitaptly/serve

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/bash
2+
set -e
3+
method="$1"
4+
path="$2"
5+
6+
if [ "$method" != GET ]; then
7+
printf 'HTTP/1.1 405 Method Forbidden\r\n\r\n'
8+
exit 0
9+
fi
10+
11+
file=$(echo "$path" | rev | cut -d/ -f1 | rev)
12+
repo=$(echo "$path" | rev | cut -d/ -f2 | rev)
13+
owner=$(echo "$path" | rev | cut -d/ -f3 | rev)
14+
15+
# if [ -f /usr/bin/opentelemetry_shell.sh ]; then
16+
# span_handle="$(otel_span_current)"
17+
# otel_span_attribute $span_handle http.route=/$owner/$repo
18+
# otel_span_attribute $span_handle github.repository.owner=$owner
19+
# otel_span_attribute $span_handle github.repository.name=$repo
20+
# otel_span_attribute $span_handle github.repository.file=$file
21+
# metric_handle=$(otel_metric_create "gitaptly.downloads")
22+
# otel_metric_attribute $metric_handle github.repository.owner=$owner
23+
# otel_metric_attribute $metric_handle github.repository.repo=$repo
24+
# otel_metric_attribute $metric_handle github.repository.file=$file
25+
# otel_metric_add $metric_handle 1
26+
# fi
27+
28+
printf 'HTTP/1.1 200 OK\r\n'
29+
printf 'content-encoding: identity\r\n'
30+
printf 'content-type: application/vnd.debian.binary-package\r\n'
31+
printf '\r\n'
32+
bash /usr/share/gitaptly/scan $owner/$repo | grep "$file"'$' | head --lines=1 | xargs wget -O -
33+
34+
# printf 'HTTP/1.1 308 Permanent Redirect\r\n'
35+
# printf 'location: ' && bash /usr/share/gitaptly/scan $owner/$repo | grep "$file"'$' | head --lines=1 && printf '\r\n'
36+
# printf '\r\n'
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#!/bin/bash -e
1+
#!/bin/bash
2+
set -e
23
source /opt/gitaptly/env
34
if [ -f /usr/bin/opentelemetry_shell.sh ]; then
45
export OTEL_SERVICE_NAME=GitAptly
@@ -17,36 +18,33 @@ if [ -f /usr/bin/opentelemetry_shell.sh ]; then
1718
fi
1819
cd /var/lib/gitaptly
1920

20-
# TODO handle if one mode is switched to the other (packages and evrything needs to be cleared and fully re-initialized)
21-
# TODO clean if deb packages are remove
22-
# TODO better recovery in proxy mode, check if Packages is there, and if not, redo a full scan
23-
24-
cat /etc/gitaptly.conf | xargs -r -I {} mkdir -p pool/main/{}
2521
if [ "$MODE" = 'cache' ]; then
26-
cat /etc/gitaptly.conf | sort -u | sort -R | parallel -q bash -c 'gitaptly_scan {} | xargs -r wget -nc -P /pool/main/{}/'
22+
cat /etc/gitaptly.conf | xargs -r -I {} mkdir -p pool/main/{}
23+
cat /etc/gitaptly.conf | sort -u | sort -R | parallel -q bash -c 'bash /usr/share/gitaptly/scan {} | xargs -r wget -nc -P pool/main/{}/'
2724
dpkg-scanpackages --multiversion pool/ > dists/stable/main/binary-all/Packages
2825
elif [ "$MODE" = 'proxy' ]; then
29-
gitaptly_proxy_process_url() {
26+
indexify() {
3027
set -e
3128
url="$*"
3229
owner="$(echo "$url" | cut -d "/" -f 4)"
3330
repo="$(echo "$url" | cut -d "/" -f 5)"
3431
file="$(echo "$url" | rev | cut -d "/" -f 1 | rev)"
35-
if [ -f cgi-bin/main/"$owner"/"$repo"/"$file" ]; then return 0; fi
36-
wget -nc -O pool/main/"$owner"/"$repo"/"$file" "$url"
37-
dpkg-scanpackages --multiversion pool/main/$owner/$repo/$file \
38-
| sed "s/Filename: .*/Filename: cgi-bin\/main\/$owner\/$repo\/$file/" \
32+
temporary="$(mktemp -d)"
33+
wget -nc -O "$temporary"/package.deb "$url"
34+
dpkg-scanpackages --multiversion "$temporary"/package.deb \
35+
| sed "s/Filename: .*/Filename: pool\/main\/$owner\/$repo\/$file/" \
3936
| flock dists/stable/main/binary-all/Packages tee -a dists/stable/main/binary-all/Packages > /dev/null
40-
rm pool/main/"$owner"/"$repo"/"$file"
41-
ln --symbolic /usr/bin/gitaptly_serve cgi-bin/main/"$owner"/"$repo"/"$file"
37+
rm -rf "$temporary"
4238
}
43-
export -f gitaptly_proxy_process_url
39+
export -f indexify
4440
touch dists/stable/main/binary-all/Packages
45-
cat /etc/gitaptly.conf | xargs -r -I {} mkdir -p cgi-bin/main/{}
46-
cat /etc/gitaptly.conf | sort -u | sort -R | parallel gitaptly_scan | parallel gitaptly_proxy_process_url
41+
index="$(mktemp)"
42+
cat dists/stable/main/binary-all/Packages | grep '^Filename: ' | cut -d ' ' -f 2- | cut -d / -f 3- | awk -F'/' '{print "^https://.*/"$1"/"$2"/.*/"$3"$"}' > "$index"
43+
cat /etc/gitaptly.conf | sort -u | sort -R | parallel bash /usr/share/gitaptly/scan | grep -v -f "$index" | parallel indexify
44+
rm "$index"
4745
else
4846
exit 1
4947
fi
5048

5149
gzip -9 < dists/stable/main/binary-all/Packages > dists/stable/main/binary-all/Packages.gz
52-
gitaptly_create_release dists/stable > dists/stable/Release
50+
bash /usr/share/gitaptly/create_release dists/stable > dists/stable/Release

package/var/lib/gitaptly/cgi-bin/main/.placeholder

-2
This file was deleted.

package/var/lib/gitaptly/pool/main/.placeholder

-2
This file was deleted.

0 commit comments

Comments
 (0)