mirror of
https://codeberg.org/scip/kleingebaeck.git
synced 2025-12-16 12:01:00 +01:00
added docker image support
* added environment variable support * added docker instructions * added .env hint
This commit is contained in:
28
.github/workflows/pushimage.yaml
vendored
Normal file
28
.github/workflows/pushimage.yaml
vendored
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
name: build-push-image
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- 'v*'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build-and-push-image:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
packages: write
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Log in to the Container registry
|
||||||
|
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
|
||||||
|
with:
|
||||||
|
registry: https://ghcr.io
|
||||||
|
username: ${{ github.actor }}
|
||||||
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
|
- name: Build and push Docker image
|
||||||
|
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
|
||||||
|
with:
|
||||||
|
push: true
|
||||||
|
tags: ghcr.io/tlinden/kleingebaeck:${{ github.ref_name}}
|
||||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -2,3 +2,4 @@ test
|
|||||||
kleingebaeck
|
kleingebaeck
|
||||||
releases
|
releases
|
||||||
t/out
|
t/out
|
||||||
|
.bak
|
||||||
|
|||||||
27
Dockerfile
Normal file
27
Dockerfile
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
FROM golang:1.21-alpine as builder
|
||||||
|
|
||||||
|
RUN apk update
|
||||||
|
RUN apk upgrade
|
||||||
|
RUN apk add --no-cache git make
|
||||||
|
|
||||||
|
RUN git --version
|
||||||
|
|
||||||
|
WORKDIR /work
|
||||||
|
|
||||||
|
COPY go.mod .
|
||||||
|
COPY . .
|
||||||
|
RUN go mod download
|
||||||
|
RUN make
|
||||||
|
|
||||||
|
FROM alpine:latest
|
||||||
|
LABEL maintainer="Thomas von Dein <git@daemon.de>"
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
COPY --from=builder /work/kleingebaeck /app/kleingebaeck
|
||||||
|
|
||||||
|
ENV KLEINGEBAECK_OUTDIR /backup
|
||||||
|
ENV LANG C.UTF-8
|
||||||
|
USER 1001:1001
|
||||||
|
|
||||||
|
ENTRYPOINT ["/app/kleingebaeck"]
|
||||||
|
CMD ["-h"]
|
||||||
34
README.md
34
README.md
@@ -94,6 +94,33 @@ installed - `make`.
|
|||||||
|
|
||||||
To install after building either copy the binary or execute `sudo make install`.
|
To install after building either copy the binary or execute `sudo make install`.
|
||||||
|
|
||||||
|
### Using the docker image
|
||||||
|
|
||||||
|
A pre-built docker image is available, which you can use to test the
|
||||||
|
app without installing it. You need `docker-compose`. Copy the file
|
||||||
|
`docker-compose.yaml` to somewhere, cd to that directory and execute:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
mkdir kleinanzeigen-backup
|
||||||
|
USER_ID=$(id -u) GROUP_ID=$(id -g) OUTDIR=./kleinanzeigen-backup docker-compose run kleingebaeck -u XXX -v
|
||||||
|
```
|
||||||
|
|
||||||
|
`USER_ID` and `GROUP_ID` needs to be specified so that you are the
|
||||||
|
owner of the created backups. The backup directory `OUTDIR` must exist
|
||||||
|
prior to the execution, otherwise docker will create it as root, then
|
||||||
|
kleingebaeck will fail. You may also use a `.env` file in the same
|
||||||
|
directory containing the variables, such as:
|
||||||
|
|
||||||
|
```
|
||||||
|
USER_ID=1000
|
||||||
|
GROUP_ID=1000
|
||||||
|
OUTDIR=./kleinanzeigen-backup
|
||||||
|
```
|
||||||
|
|
||||||
|
You may of course also modify the `docker-compose.yaml` to suit your needs.
|
||||||
|
|
||||||
|
If you want to build the image yourself, use the supplied Dockerfile.
|
||||||
|
|
||||||
## Commandline options:
|
## Commandline options:
|
||||||
|
|
||||||
```
|
```
|
||||||
@@ -128,6 +155,13 @@ loglevel = verbose
|
|||||||
outdir = "test"
|
outdir = "test"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Environment Variables
|
||||||
|
|
||||||
|
Kleingebaeck can also be configured using environment variables. Just prefix the config variables with `KLEINGEBAECK_` and put them to upper case. Eg:
|
||||||
|
```shell
|
||||||
|
% KLEINGEBAECK_OUTDIR=/backup kleingebaeck -v
|
||||||
|
```
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
To setup the tool, you need to lookup your userid on
|
To setup the tool, you need to lookup your userid on
|
||||||
|
|||||||
12
config.go
12
config.go
@@ -23,9 +23,11 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/knadh/koanf/parsers/toml"
|
"github.com/knadh/koanf/parsers/toml"
|
||||||
"github.com/knadh/koanf/providers/confmap"
|
"github.com/knadh/koanf/providers/confmap"
|
||||||
|
"github.com/knadh/koanf/providers/env"
|
||||||
"github.com/knadh/koanf/providers/file"
|
"github.com/knadh/koanf/providers/file"
|
||||||
"github.com/knadh/koanf/providers/posflag"
|
"github.com/knadh/koanf/providers/posflag"
|
||||||
"github.com/knadh/koanf/v2"
|
"github.com/knadh/koanf/v2"
|
||||||
@@ -162,7 +164,15 @@ func InitConfig(w io.Writer) (*Config, error) {
|
|||||||
// else: we ignore the file if it doesn't exists
|
// else: we ignore the file if it doesn't exists
|
||||||
}
|
}
|
||||||
|
|
||||||
// command line overrides config file
|
// env overrides config file
|
||||||
|
if err := k.Load(env.Provider("KLEINGEBAECK_", ".", func(s string) string {
|
||||||
|
return strings.Replace(strings.ToLower(
|
||||||
|
strings.TrimPrefix(s, "KLEINGEBAECK_")), "_", ".", -1)
|
||||||
|
}), nil); err != nil {
|
||||||
|
return nil, errors.New("error loading environment: " + err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
// command line overrides env
|
||||||
if err := k.Load(posflag.Provider(f, ".", k), nil); err != nil {
|
if err := k.Load(posflag.Provider(f, ".", k), nil); err != nil {
|
||||||
return nil, errors.New("error loading flags: " + err.Error())
|
return nil, errors.New("error loading flags: " + err.Error())
|
||||||
}
|
}
|
||||||
|
|||||||
22
docker-compose.yaml
Normal file
22
docker-compose.yaml
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
version: "3.9"
|
||||||
|
services:
|
||||||
|
init:
|
||||||
|
image: alpine:latest
|
||||||
|
user: "root"
|
||||||
|
group_add:
|
||||||
|
- '${GROUP_ID}'
|
||||||
|
volumes:
|
||||||
|
- ${OUTDIR}:/backup
|
||||||
|
command: chown -R ${USER_ID}:${USER_ID} /backup
|
||||||
|
|
||||||
|
kleingebaeck:
|
||||||
|
container_name: kleingebaeck
|
||||||
|
user: "${USER_ID}:${USER_ID}"
|
||||||
|
volumes:
|
||||||
|
- ${OUTDIR}:/backup
|
||||||
|
working_dir: /backup
|
||||||
|
build: .
|
||||||
|
image: kleingebaeck:latest
|
||||||
|
depends_on:
|
||||||
|
init:
|
||||||
|
condition: service_completed_successfully
|
||||||
1
go.mod
1
go.mod
@@ -21,6 +21,7 @@ require (
|
|||||||
github.com/andybalholm/cascadia v1.0.0 // indirect
|
github.com/andybalholm/cascadia v1.0.0 // indirect
|
||||||
github.com/fsnotify/fsnotify v1.6.0 // indirect
|
github.com/fsnotify/fsnotify v1.6.0 // indirect
|
||||||
github.com/knadh/koanf/maps v0.1.1 // indirect
|
github.com/knadh/koanf/maps v0.1.1 // indirect
|
||||||
|
github.com/knadh/koanf/providers/env v0.1.0 // indirect
|
||||||
github.com/mitchellh/copystructure v1.2.0 // indirect
|
github.com/mitchellh/copystructure v1.2.0 // indirect
|
||||||
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
||||||
github.com/mitchellh/reflectwalk v1.0.2 // indirect
|
github.com/mitchellh/reflectwalk v1.0.2 // indirect
|
||||||
|
|||||||
2
go.sum
2
go.sum
@@ -17,6 +17,8 @@ github.com/knadh/koanf/parsers/toml v0.1.0 h1:S2hLqS4TgWZYj4/7mI5m1CQQcWurxUz6OD
|
|||||||
github.com/knadh/koanf/parsers/toml v0.1.0/go.mod h1:yUprhq6eo3GbyVXFFMdbfZSo928ksS+uo0FFqNMnO18=
|
github.com/knadh/koanf/parsers/toml v0.1.0/go.mod h1:yUprhq6eo3GbyVXFFMdbfZSo928ksS+uo0FFqNMnO18=
|
||||||
github.com/knadh/koanf/providers/confmap v0.1.0 h1:gOkxhHkemwG4LezxxN8DMOFopOPghxRVp7JbIvdvqzU=
|
github.com/knadh/koanf/providers/confmap v0.1.0 h1:gOkxhHkemwG4LezxxN8DMOFopOPghxRVp7JbIvdvqzU=
|
||||||
github.com/knadh/koanf/providers/confmap v0.1.0/go.mod h1:2uLhxQzJnyHKfxG927awZC7+fyHFdQkd697K4MdLnIU=
|
github.com/knadh/koanf/providers/confmap v0.1.0/go.mod h1:2uLhxQzJnyHKfxG927awZC7+fyHFdQkd697K4MdLnIU=
|
||||||
|
github.com/knadh/koanf/providers/env v0.1.0 h1:LqKteXqfOWyx5Ab9VfGHmjY9BvRXi+clwyZozgVRiKg=
|
||||||
|
github.com/knadh/koanf/providers/env v0.1.0/go.mod h1:RE8K9GbACJkeEnkl8L/Qcj8p4ZyPXZIQ191HJi44ZaQ=
|
||||||
github.com/knadh/koanf/providers/file v0.1.0 h1:fs6U7nrV58d3CFAFh8VTde8TM262ObYf3ODrc//Lp+c=
|
github.com/knadh/koanf/providers/file v0.1.0 h1:fs6U7nrV58d3CFAFh8VTde8TM262ObYf3ODrc//Lp+c=
|
||||||
github.com/knadh/koanf/providers/file v0.1.0/go.mod h1:rjJ/nHQl64iYCtAW2QQnF0eSmDEX/YZ/eNFj5yR6BvA=
|
github.com/knadh/koanf/providers/file v0.1.0/go.mod h1:rjJ/nHQl64iYCtAW2QQnF0eSmDEX/YZ/eNFj5yR6BvA=
|
||||||
github.com/knadh/koanf/providers/posflag v0.1.0 h1:mKJlLrKPcAP7Ootf4pBZWJ6J+4wHYujwipe7Ie3qW6U=
|
github.com/knadh/koanf/providers/posflag v0.1.0 h1:mKJlLrKPcAP7Ootf4pBZWJ6J+4wHYujwipe7Ie3qW6U=
|
||||||
|
|||||||
@@ -133,7 +133,7 @@
|
|||||||
.\" ========================================================================
|
.\" ========================================================================
|
||||||
.\"
|
.\"
|
||||||
.IX Title "KLEINGEBAECK 1"
|
.IX Title "KLEINGEBAECK 1"
|
||||||
.TH KLEINGEBAECK 1 "2024-01-16" "1" "User Commands"
|
.TH KLEINGEBAECK 1 "2024-01-17" "1" "User Commands"
|
||||||
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
|
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
|
||||||
.\" way too many mistakes in technical documents.
|
.\" way too many mistakes in technical documents.
|
||||||
.if n .ad l
|
.if n .ad l
|
||||||
@@ -219,6 +219,22 @@ directory. Then just execute \f(CW\*(C`kleingebaeck\*(C'\fR.
|
|||||||
.PP
|
.PP
|
||||||
You can use the \fB\-v\fR option to get verbose output or \fB\-d\fR to enable
|
You can use the \fB\-v\fR option to get verbose output or \fB\-d\fR to enable
|
||||||
debugging.
|
debugging.
|
||||||
|
.SH "ENVIRONMENT VARIABLES"
|
||||||
|
.IX Header "ENVIRONMENT VARIABLES"
|
||||||
|
The following environment variables are considered:
|
||||||
|
.PP
|
||||||
|
.Vb 7
|
||||||
|
\& KLEINGEBAECK_USER
|
||||||
|
\& KLEINGEBAECK_DEBUG
|
||||||
|
\& KLEINGEBAECK_VERBOSE
|
||||||
|
\& KLEINGEBAECK_OUTDIR
|
||||||
|
\& KLEINGEBAECK_LIMIT
|
||||||
|
\& KLEINGEBAECK_CONFIG
|
||||||
|
\& KLEINGEBAECK_IGNOREERRORS
|
||||||
|
.Ve
|
||||||
|
.PP
|
||||||
|
Please note, that they take precedence over config file, but
|
||||||
|
commandline flags take precedence over env!
|
||||||
.SH "BUGS"
|
.SH "BUGS"
|
||||||
.IX Header "BUGS"
|
.IX Header "BUGS"
|
||||||
In order to report a bug, unexpected behavior, feature requests
|
In order to report a bug, unexpected behavior, feature requests
|
||||||
|
|||||||
@@ -74,6 +74,20 @@ SETUP
|
|||||||
You can use the -v option to get verbose output or -d to enable
|
You can use the -v option to get verbose output or -d to enable
|
||||||
debugging.
|
debugging.
|
||||||
|
|
||||||
|
ENVIRONMENT VARIABLES
|
||||||
|
The following environment variables are considered:
|
||||||
|
|
||||||
|
KLEINGEBAECK_USER
|
||||||
|
KLEINGEBAECK_DEBUG
|
||||||
|
KLEINGEBAECK_VERBOSE
|
||||||
|
KLEINGEBAECK_OUTDIR
|
||||||
|
KLEINGEBAECK_LIMIT
|
||||||
|
KLEINGEBAECK_CONFIG
|
||||||
|
KLEINGEBAECK_IGNOREERRORS
|
||||||
|
|
||||||
|
Please note, that they take precedence over config file, but commandline
|
||||||
|
flags take precedence over env!
|
||||||
|
|
||||||
BUGS
|
BUGS
|
||||||
In order to report a bug, unexpected behavior, feature requests or to
|
In order to report a bug, unexpected behavior, feature requests or to
|
||||||
submit a patch, please open an issue on github:
|
submit a patch, please open an issue on github:
|
||||||
|
|||||||
@@ -77,6 +77,23 @@ directory. Then just execute C<kleingebaeck>.
|
|||||||
You can use the B<-v> option to get verbose output or B<-d> to enable
|
You can use the B<-v> option to get verbose output or B<-d> to enable
|
||||||
debugging.
|
debugging.
|
||||||
|
|
||||||
|
=head1 ENVIRONMENT VARIABLES
|
||||||
|
|
||||||
|
The following environment variables are considered:
|
||||||
|
|
||||||
|
KLEINGEBAECK_USER
|
||||||
|
KLEINGEBAECK_DEBUG
|
||||||
|
KLEINGEBAECK_VERBOSE
|
||||||
|
KLEINGEBAECK_OUTDIR
|
||||||
|
KLEINGEBAECK_LIMIT
|
||||||
|
KLEINGEBAECK_CONFIG
|
||||||
|
KLEINGEBAECK_IGNOREERRORS
|
||||||
|
|
||||||
|
Please note, that they take precedence over config file, but
|
||||||
|
commandline flags take precedence over env!
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
=head1 BUGS
|
=head1 BUGS
|
||||||
|
|
||||||
In order to report a bug, unexpected behavior, feature requests
|
In order to report a bug, unexpected behavior, feature requests
|
||||||
|
|||||||
Reference in New Issue
Block a user