mirror of
https://codeberg.org/scip/ephemerup.git
synced 2025-12-16 12:10:58 +01:00
reorg dir structure, add docker image build
This commit is contained in:
33
Dockerfile
Normal file
33
Dockerfile
Normal file
@@ -0,0 +1,33 @@
|
||||
# syntax=docker/dockerfile:1 -*-python-*-
|
||||
FROM golang:1.20-alpine as builder
|
||||
|
||||
RUN apk update
|
||||
RUN apk upgrade
|
||||
RUN apk add --no-cache git make bash binutils
|
||||
|
||||
RUN git --version
|
||||
|
||||
WORKDIR /work
|
||||
|
||||
COPY go.mod .
|
||||
RUN go mod download
|
||||
COPY . .
|
||||
RUN make && strip upd
|
||||
|
||||
FROM alpine:3.17
|
||||
LABEL maintainer="Uploads Author <info@daemon.de>"
|
||||
|
||||
RUN install -o 1001 -g 1001 -d /data
|
||||
|
||||
WORKDIR /app
|
||||
COPY --from=builder /work/upd /app/upd
|
||||
|
||||
ENV UPD_LISTEN=:8080
|
||||
ENV UPD_STORAGEDIR=/data
|
||||
ENV UPD_DBFILE=/data/bbolt.db
|
||||
ENV UPD_DEBUG=1
|
||||
|
||||
USER 1001:1001
|
||||
EXPOSE 8080
|
||||
VOLUME /data
|
||||
CMD ["/app/upd"]
|
||||
79
Makefile
79
Makefile
@@ -1,7 +1,76 @@
|
||||
all:
|
||||
make -C upd
|
||||
make -C upctl
|
||||
|
||||
# Copyright © 2023 Thomas von Dein
|
||||
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
#
|
||||
# no need to modify anything below
|
||||
tool = upd
|
||||
version = $(shell egrep "= .v" cfg/config.go | cut -d'=' -f2 | cut -d'"' -f 2)
|
||||
archs = android darwin freebsd linux netbsd openbsd windows
|
||||
PREFIX = /usr/local
|
||||
UID = root
|
||||
GID = 0
|
||||
BRANCH = $(shell git branch --show-current)
|
||||
COMMIT = $(shell git rev-parse --short=8 HEAD)
|
||||
BUILD = $(shell date +%Y.%m.%d.%H%M%S)
|
||||
VERSION := $(if $(filter $(BRANCH), development),$(version)-$(BRANCH)-$(COMMIT)-$(BUILD),$(version))
|
||||
HAVE_POD := $(shell pod2text -h 2>/dev/null)
|
||||
|
||||
all: buildlocal
|
||||
|
||||
buildlocal:
|
||||
go build -ldflags "-X 'github.com/tlinden/up/upd/cfg.VERSION=$(VERSION)'"
|
||||
|
||||
buildimage: clean
|
||||
docker-compose --verbose build
|
||||
|
||||
release:
|
||||
./mkrel.sh $(tool) $(version)
|
||||
gh release create $(version) --generate-notes releases/*
|
||||
|
||||
install: buildlocal
|
||||
install -d -o $(UID) -g $(GID) $(PREFIX)/bin
|
||||
install -o $(UID) -g $(GID) -m 555 $(tool) $(PREFIX)/sbin/
|
||||
|
||||
clean:
|
||||
make -C upd clean
|
||||
make -C upctl clean
|
||||
rm -rf $(tool) releases coverage.out
|
||||
|
||||
test:
|
||||
go test -v ./...
|
||||
# bash t/test.sh
|
||||
|
||||
singletest:
|
||||
@echo "Call like this: ''make singletest TEST=TestX1 MOD=lib"
|
||||
go test -run $(TEST) github.com/tlinden/upd/$(MOD)
|
||||
|
||||
cover-report:
|
||||
go test ./... -cover -coverprofile=coverage.out
|
||||
go tool cover -html=coverage.out
|
||||
|
||||
show-versions: buildlocal
|
||||
@echo "### upd version:"
|
||||
@./upd --version
|
||||
|
||||
@echo
|
||||
@echo "### go module versions:"
|
||||
@go list -m all
|
||||
|
||||
@echo
|
||||
@echo "### go version used for building:"
|
||||
@grep -m 1 go go.mod
|
||||
|
||||
goupdate:
|
||||
go get -t -u=patch ./...
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
# syntax=docker/dockerfile:1 -*-python-*-
|
||||
FROM golang:1.18-alpine
|
||||
ARG VERSION
|
||||
LABEL upd_version=0.1
|
||||
|
||||
ENV HOME="/" \
|
||||
OS_ARCH="amd64" \
|
||||
OS_FLAVOUR="alpine" \
|
||||
OS_NAME="linux"
|
||||
|
||||
RUN echo $VERSION
|
||||
RUN install -o 1001 -g 1001 -d /data
|
||||
|
||||
WORKDIR /build
|
||||
RUN mkdir -p api cfg cmd
|
||||
COPY upd/api/* ./api/
|
||||
COPY upd/cfg/* ./cfg/
|
||||
COPY upd/cmd/* ./cmd/
|
||||
COPY upd/*.* ./
|
||||
RUN go mod tidy
|
||||
#RUN echo $VERSION
|
||||
# doesn't work, see
|
||||
# https://blog.alexellis.io/inject-build-time-vars-golang/
|
||||
RUN go build -ldflags "-X upd/cfg.VERSION=$VERSION"
|
||||
RUN echo $VERSION > version
|
||||
RUN ls -l
|
||||
|
||||
|
||||
WORKDIR /app
|
||||
RUN cp /build/upd /app/upd
|
||||
#RUN rm -rf /build
|
||||
|
||||
ENV UPD_LISTEN=:8080
|
||||
ENV UPD_STORAGEDIR=/data
|
||||
ENV UPD_DBFILE=/data/bbolt.db
|
||||
ENV UPD_DEBUG=1
|
||||
|
||||
USER 1001:1001
|
||||
EXPOSE 8080
|
||||
VOLUME /data
|
||||
CMD ["/app/upd"]
|
||||
@@ -1,14 +0,0 @@
|
||||
upd = ../upd/upd
|
||||
version = $(shell egrep "= .v" ../upd/cfg/config.go | cut -d'=' -f2 | cut -d'"' -f 2)
|
||||
BRANCH = $(shell git branch --show-current)
|
||||
COMMIT = $(shell git rev-parse --short=8 HEAD)
|
||||
BUILD = $(shell date +%Y.%m.%d.%H%M%S)
|
||||
VERSION := $(if $(filter $(BRANCH), development),$(version)-$(BRANCH)-$(COMMIT)-$(BUILD),$(version))
|
||||
|
||||
v:
|
||||
@echo $(VERSION)
|
||||
|
||||
build:
|
||||
cp -a ../updlocal upd
|
||||
make -C upd clean
|
||||
docker-compose build --build-arg VERSION=$(VERSION)
|
||||
74
upd/Makefile
74
upd/Makefile
@@ -1,74 +0,0 @@
|
||||
|
||||
# Copyright © 2023 Thomas von Dein
|
||||
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
#
|
||||
# no need to modify anything below
|
||||
tool = upd
|
||||
version = $(shell egrep "= .v" cfg/config.go | cut -d'=' -f2 | cut -d'"' -f 2)
|
||||
archs = android darwin freebsd linux netbsd openbsd windows
|
||||
PREFIX = /usr/local
|
||||
UID = root
|
||||
GID = 0
|
||||
BRANCH = $(shell git branch --show-current)
|
||||
COMMIT = $(shell git rev-parse --short=8 HEAD)
|
||||
BUILD = $(shell date +%Y.%m.%d.%H%M%S)
|
||||
VERSION := $(if $(filter $(BRANCH), development),$(version)-$(BRANCH)-$(COMMIT)-$(BUILD),$(version))
|
||||
HAVE_POD := $(shell pod2text -h 2>/dev/null)
|
||||
|
||||
all: buildlocal
|
||||
|
||||
|
||||
buildlocal:
|
||||
go build -ldflags "-X 'github.com/tlinden/up/upd/cfg.VERSION=$(VERSION)'"
|
||||
|
||||
release:
|
||||
./mkrel.sh $(tool) $(version)
|
||||
gh release create $(version) --generate-notes releases/*
|
||||
|
||||
install: buildlocal
|
||||
install -d -o $(UID) -g $(GID) $(PREFIX)/bin
|
||||
install -o $(UID) -g $(GID) -m 555 $(tool) $(PREFIX)/sbin/
|
||||
|
||||
clean:
|
||||
rm -rf $(tool) releases coverage.out
|
||||
|
||||
test:
|
||||
go test -v ./...
|
||||
# bash t/test.sh
|
||||
|
||||
singletest:
|
||||
@echo "Call like this: ''make singletest TEST=TestX1 MOD=lib"
|
||||
go test -run $(TEST) github.com/tlinden/upd/$(MOD)
|
||||
|
||||
cover-report:
|
||||
go test ./... -cover -coverprofile=coverage.out
|
||||
go tool cover -html=coverage.out
|
||||
|
||||
show-versions: buildlocal
|
||||
@echo "### upd version:"
|
||||
@./upd --version
|
||||
|
||||
@echo
|
||||
@echo "### go module versions:"
|
||||
@go list -m all
|
||||
|
||||
@echo
|
||||
@echo "### go version used for building:"
|
||||
@grep -m 1 go go.mod
|
||||
|
||||
goupdate:
|
||||
go get -t -u=patch ./...
|
||||
@@ -1,20 +0,0 @@
|
||||
## Test the server
|
||||
|
||||
### single file upload
|
||||
|
||||
curl -X POST localhost:8080/api/putfile -F "upload[]=@/home/scip/2023-02-06_10-51.png" -H "Content-Type: multipart/form-data"
|
||||
|
||||
get with:
|
||||
|
||||
curl -o x http://localhost:8080/api/getfile/05988587-cc1c-4590-9dc0-564b8a912686/2023-02-06_10-51.png
|
||||
|
||||
### multiple files upload
|
||||
|
||||
curl -X POST localhost:8080/api/putfile -F "upload[]=@/home/scip/2023-02-06_10-51.png" -F "upload[]=@/home/scip/pgstat.png" -H "Content-Type: multipart/form-data"
|
||||
|
||||
## TODO
|
||||
|
||||
- return HTTP errors as JSON as well
|
||||
- add auto expire customization, e.g. expire after 1 day
|
||||
- add cleanup storage per api call (single id and everything)
|
||||
- add oauth2
|
||||
Reference in New Issue
Block a user