Skip to content

Commit e0ef776

Browse files
committed
services/pkg/lego: Add a lego service container
1 parent 77e83e2 commit e0ef776

3 files changed

Lines changed: 84 additions & 0 deletions

File tree

.github/workflows/pkg-lego.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: LEGO Service Container
2+
on:
3+
workflow_dispatch:
4+
inputs:
5+
version:
6+
description: "Version tag"
7+
required: true
8+
9+
jobs:
10+
main:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout repo
14+
uses: actions/checkout@master
15+
- name: Set up QEMU
16+
uses: docker/setup-qemu-action@v1
17+
- name: Set up Docker Buildx
18+
uses: docker/setup-buildx-action@v1
19+
- name: Login to GCHR
20+
uses: docker/login-action@v1
21+
with:
22+
registry: ghcr.io
23+
username: ${{ github.actor }}
24+
password: ${{ secrets.GITHUB_TOKEN }}
25+
- name: Build and push
26+
id: docker_build
27+
uses: docker/build-push-action@v2
28+
with:
29+
context: services/pkg/lego
30+
push: true
31+
tags: "ghcr.io/void-linux/infra-lego:${{ github.event.inputs.version }}"
32+
labels: |
33+
org.opencontainers.image.source=${{ github.repositoryUrl }}

services/pkg/lego/Dockerfile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FROM ghcr.io/void-linux/void-linux:latest-thin-x86_64
2+
3+
RUN xbps-install -Sy && xbps-install -y lego vault binutils upx findutils diffutils && \
4+
strip /usr/bin/vault && upx /usr/bin/vault && \
5+
xbps-remove -Roy binutils upx && \
6+
rm -rf /var/cache/xbps
7+
WORKDIR /lego
8+
ENV ACTION=renew
9+
COPY lego.sh /entrypoint
10+
ENTRYPOINT ["/entrypoint"]

services/pkg/lego/lego.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/bin/sh
2+
3+
: "${ACTION:=renew}"
4+
: "${SERVER:=https://acme-v02.api.letsencrypt.org/directory}"
5+
6+
handle_path() {
7+
vault kv list "$1" | tail -n +3 | while read -r path ; do
8+
case "$path" in
9+
*/)
10+
mkdir -p "$1/$path"
11+
handle_path "$1/$path"
12+
;;
13+
*)
14+
vault kv get -field contents "$1$path" > "$1$path"
15+
;;
16+
esac
17+
done
18+
}
19+
20+
printf "Retrieving existing data from Vault\n"
21+
mkdir -p secret/lego/data
22+
handle_path secret/lego/data
23+
cp -r secret/lego/data pre-run
24+
25+
26+
# Need to dynamically choose whether to run or renew here. Plausibly
27+
# easier to just run it once and then change the arguments.
28+
lego \
29+
--accept-tos \
30+
--email maldridge@voidlinux.org \
31+
--path secret/lego/data \
32+
--dns digitalocean \
33+
--domains '*.voidlinux.org' \
34+
--domains '*.s.voidlinux.org' \
35+
--server $SERVER \
36+
$ACTION
37+
38+
if ! diff -rq pre-run secret/lego/data ; then
39+
printf "Uploading new data to Vault\n"
40+
find secret/lego/data -type f -exec vault kv put {} contents=@{} \;
41+
fi

0 commit comments

Comments
 (0)