all repos — disgord @ 451c462955a02ed969386fe816392b8e1fc1cfe2

A simple Discord bot in Go.

update Dockerfile, add makefile
Marco Andronaco andronacomarco@gmail.com
Fri, 04 Oct 2024 22:31:13 +0200
commit

451c462955a02ed969386fe816392b8e1fc1cfe2

parent

4594fc1f9738dd7c5e7d9ec50660b347f0d3a6d2

2 files changed, 38 insertions(+), 7 deletions(-)

jump to
M DockerfileDockerfile

@@ -2,7 +2,6 @@ # syntax=docker/dockerfile:1

FROM golang:1.23-alpine AS builder -# RUN apk add --no-cache git WORKDIR /build

@@ -22,7 +21,7 @@ COPY src ./src

# Build RUN commit_hash=$(cat commitID | cut -c1-7) && \ - CGO_ENABLED=0 go build -ldflags "-X github.com/BiRabittoh/disgord/src.CommitID=$commit_hash" -trimpath -o /dist/app + CGO_ENABLED=0 go build -ldflags "-X github.com/BiRabittoh/disgord/src/globals.CommitID=$commit_hash" -trimpath -o /dist/app # Test

@@ -30,13 +29,11 @@ FROM builder AS run-test-stage

# COPY i18n ./i18n RUN go test -v ./... -FROM scratch AS build-release-stage +FROM alpine AS build-release-stage + +RUN apk add --no-cache ffmpeg WORKDIR /app -COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ COPY --from=builder /dist . -# COPY i18n ./i18n -# COPY publi[c] ./public - ENTRYPOINT ["./app"]
A Makefile

@@ -0,0 +1,34 @@

+# Variables +APP_NAME=disgord +COMMIT_HASH=$(shell git rev-parse --short HEAD) +BUILD_DIR=dist +SRC_DIR=src + +# Build flags for versioning +LDFLAGS=-ldflags "-X github.com/BiRabittoh/disgord/src/globals.CommitID=$(COMMIT_HASH)" + +.PHONY: all build test run clean + +# Default command: build the application +all: build + +# Build the Go application +build: + @echo "Building $(APP_NAME)..." + @mkdir -p $(BUILD_DIR) + CGO_ENABLED=0 go build $(LDFLAGS) -trimpath -o $(BUILD_DIR)/$(APP_NAME) + +# Run tests +test: + @echo "Running tests..." + go test -v ./... + +# Run the application +run: + @echo "Running $(APP_NAME)..." + go run . + +# Clean up build artifacts +clean: + @echo "Cleaning up..." + @rm -rf $(BUILD_DIR)