feat: Major refactor, implement web, caching, better tests and build files

* Update golang version to 1.24
* Update multiarch Dockerfile to be more ISA agnostic
* Refactor existing code and properly structure project into modules
* Get rid of global variables except where necessary (go:embed)
* Add default values to Config
* Add webserver with templates to finally correctly serve videos and gifs
* Add tiny caching library to decrease api load and improve latency
* Improve Webhook data preparation by filtering out redundant links
  from the tweet text and properly attaching videos and gifs in separate
  webhook request by utilising new webserver
* Improve tests for filter function
* Improve bake definition for easier CI integration
This commit is contained in:
Manuel 2025-03-18 19:22:00 +01:00
parent 7562b86894
commit 21d580d1a6
Signed by: Manuel
GPG key ID: 4085037435E1F07A
24 changed files with 752 additions and 209 deletions

View file

@ -1,8 +1,8 @@
FROM --platform=linux/amd64 golang:1.22 AS build
FROM --platform=$BUILDPLATFORM golang:1.24 AS build
ARG TARGETOS TARGETARCH TARGETVARIANT
ENV GOOS $TARGETOS
ENV GOARCH $TARGETARCH
ARG GOOS=$TARGETOS
ARG GOARCH=$TARGETARCH
RUN apt-get update && \
apt-get install -y --no-install-recommends ca-certificates && \
@ -10,8 +10,8 @@ RUN apt-get update && \
"arm64") apt-get install -y gcc-aarch64-linux-gnu ;; \
"armv7") apt-get install -y gcc-arm-linux-gnueabihf ;; \
"riscv64") apt-get install -y gcc-riscv64-linux-gnu ;; \
"amd64") apt-get install -y gcc ;; \
*) echo "Arch not supported" && exit 1 ;; \
"amd64") apt-get install -y gcc-x86-64-linux-gnu ;; \
*) echo "Arch '$TARGETARCH$TARGETVARIANT' not supported" && exit 1 ;; \
esac
WORKDIR /tmp/app
@ -21,14 +21,14 @@ RUN go mod download && \
"arm64") export CC="aarch64-linux-gnu-gcc" PIE=true ;; \
"armv7") export CC="arm-linux-gnueabihf-gcc" GOARM="7" ;; \
"riscv64") export CC="riscv64-linux-gnu-gcc" ;; \
"amd64") export CC="gcc" PIE=true ;; \
*) echo "Arch not supported" && exit 1 ;; \
"amd64") export CC="x86_64-linux-gnu-gcc" PIE=true ;; \
*) echo "Arch '$TARGETARCH$TARGETVARIANT' not supported" && exit 1 ;; \
esac && \
export CGO_ENABLED=1 && \
if [ $PIE = true ]; then \
go build -a -buildmode=pie -trimpath -ldflags "-s -w -linkmode 'external' -extldflags '-static-pie' -X main.prefix=" -o discord-tweeter; \
export CGO_ENABLED=1 LDFLAGS="-s -w -linkmode 'external'" && \
if [ "$PIE" = "true" ]; then \
go build -a -buildmode=pie -trimpath -ldflags "$LDFLAGS -extldflags '-static-pie' -X main.prefix=" -o discord-tweeter; \
else \
go build -a -trimpath -ldflags "-s -w -linkmode 'external' -extldflags '-static' -X main.prefix=" -o discord-tweeter; \
go build -a -trimpath -ldflags "$LDFLAGS -extldflags '-static' -X main.prefix=" -o discord-tweeter; \
fi
FROM scratch
@ -40,4 +40,4 @@ COPY --from=build /tmp/app/discord-tweeter .
#COPY ./config.example.toml ./config.toml
ENTRYPOINT [ "./discord-tweeter" ]
# CMD [ "./config.toml" ]
#CMD [ "./config.toml" ]