Big refactor

This commit is contained in:
Ben Sarmiento
2023-11-14 01:55:00 +01:00
parent 5e723a9e8a
commit 16505ec33f
26 changed files with 1602 additions and 453 deletions

View File

@@ -6,14 +6,15 @@ ARG GOARCH=amd64
FROM golang:1-alpine AS builder
WORKDIR /app
COPY . .
RUN CGO_ENABLED=0 GOOS=${GOOS} GOARCH=${GOARCH} go build -ldflags="-s -w" -o zurg cmd/zurg/main.go
RUN apk add --no-cache bash git go gcc musl-dev curl fuse
RUN go build -o zurg cmd/zurg/main.go
# Obfuscation stage
FROM alpine:3 AS obfuscator
WORKDIR /app
COPY --from=builder /app/zurg .
# RUN apk add --no-cache upx
# RUN upx --brute zurg
RUN apk add --no-cache upx
RUN upx --brute zurg
# Create a health check script that extracts the port from the config file
RUN echo $'#!/bin/sh\n\
port=$(yaml read /app/config.yml port)\n\
@@ -24,19 +25,6 @@ nc -z localhost $port || exit 1' > /app/healthcheck.sh && \
FROM alpine:3
WORKDIR /app
# Accept UID and GID as build arguments with default values
ARG UID=1000
ARG GID=1000
# Add a group with the specified GID
RUN addgroup -g ${GID} appgroup
# Add a user with the specified UID and add to the group
RUN adduser -u ${UID} -D -G appgroup appuser
# Change the ownership of the /app directory to the appuser
RUN chown -R appuser:appgroup /app
# Copy the obfuscated binary from the obfuscator stage
COPY --from=obfuscator /app/zurg .
COPY --from=obfuscator /app/healthcheck.sh .
@@ -48,9 +36,6 @@ COPY config.yml.example /app/config.yml
RUN apk add --no-cache fuse3 netcat-openbsd yaml-cpp \
&& echo 'user_allow_other' >> /etc/fuse.conf
# Use the non-root user to run the application
USER appuser
# Use the script for the health check
HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 CMD /app/healthcheck.sh