Skip to content

Commit a2d1751

Browse files
Created genMongoLoad go app to replace python version
1 parent e721758 commit a2d1751

40 files changed

+3556
-3036
lines changed

.github/workflows/release.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Build and Release
2+
# Trigger this workflow only when a tag starting with 'v' is pushed
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
permissions:
8+
contents: write
9+
jobs:
10+
release:
11+
name: Build and Release
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v4
16+
17+
- name: Set up Go
18+
uses: actions/setup-go@v4
19+
with:
20+
go-version: '1.25' # Check your go.mod for the correct version
21+
22+
- name: Build and Package
23+
# This runs the target we just created in your Makefile
24+
run: make build
25+
26+
- name: Create Release
27+
uses: softprops/action-gh-release@v1
28+
with:
29+
# This tells GitHub to pick up any tar.gz file in the bin folder
30+
files: bin/*.tar.gz
31+
env:
32+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,18 @@
11
__pycache__*
2-
mongodbCreds.py
2+
todo.txt
3+
# Binaries
4+
# Ignore all binaries in the bin folder
5+
bin/
6+
7+
# OS Specific
8+
.DS_Store
9+
Thumbs.db
10+
11+
# IDE / Editor
12+
.vscode/
13+
.idea/
14+
*.swp
15+
16+
# Go specific
17+
vendor/
18+
go.sum

Dockerfile

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# --- Stage 1: Builder ---
2+
# We use the official Go image to compile the code
3+
FROM golang:1.25 AS builder
4+
5+
# Set the working directory inside the container
6+
WORKDIR /app
7+
8+
# Copy all your source code into the container
9+
COPY . .
10+
11+
# Disable CGO to ensure the binary runs on Alpine Linux
12+
ENV CGO_ENABLED=0
13+
14+
# Build the binary
15+
# We target main.go
16+
RUN go build -o genMongoLoad cmd/genMongoLoad/main.go
17+
18+
# --- Stage 2: Runner ---
19+
# We use a tiny Alpine Linux image for the final container
20+
FROM alpine:latest
21+
22+
WORKDIR /app
23+
24+
# Copy the compiled binary from the builder stage
25+
COPY --from=builder /app/genMongoLoad .
26+
27+
# Copy the config file so the app can read it
28+
COPY config.yaml .
29+
30+
# Also copy the resources folder so we have access to all queries/collections
31+
COPY resources/ resources/
32+
33+
# Command to run when the container starts
34+
CMD ["./genMongoLoad", "config.yaml"]

Makefile

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# --- Variables ---
2+
APP_NAME := genMongoLoad
3+
SRC_DIR := cmd/genMongoLoad/main.go
4+
BIN_DIR := bin
5+
6+
# Get the latest git tag or commit hash.
7+
VERSION := $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
8+
9+
# Linker flags to inject the version.
10+
# -s -w strips debugging information to make the binary smaller (good for static builds).
11+
LDFLAGS := -ldflags "-s -w -X main.version=$(VERSION)"
12+
13+
# --- Commands ---
14+
15+
.PHONY: all build build-linux build-mac clean run help
16+
17+
# Default target
18+
all: build
19+
20+
# Build and Package for all platforms
21+
build: clean build-linux build-mac
22+
@echo "All builds and packages complete. Artifacts are in $(BIN_DIR)/"
23+
24+
# Build and Package for Linux (CentOS, RHEL, Ubuntu, Debian, etc.)
25+
build-linux:
26+
@echo "Building and packaging $(APP_NAME) for Linux (amd64)..."
27+
@mkdir -p $(BIN_DIR)
28+
# CGO_ENABLED=0 creates a static binary that runs on CentOS/RHEL/Alpine
29+
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build $(LDFLAGS) -o $(BIN_DIR)/$(APP_NAME)-linux-amd64 $(SRC_DIR)
30+
tar -czvf $(BIN_DIR)/$(APP_NAME)-linux-amd64.tar.gz -C $(BIN_DIR) $(APP_NAME)-linux-amd64
31+
32+
# Build and Package for Mac
33+
build-mac:
34+
@echo "Building and packaging $(APP_NAME) for Mac..."
35+
@mkdir -p $(BIN_DIR)
36+
37+
# Mac Intel (amd64)
38+
# CGO is usually required for Mac system calls, so we keep it enabled (default) or rely on pure Go.
39+
GOOS=darwin GOARCH=amd64 go build $(LDFLAGS) -o $(BIN_DIR)/$(APP_NAME)-darwin-amd64 $(SRC_DIR)
40+
tar -czvf $(BIN_DIR)/$(APP_NAME)-darwin-amd64.tar.gz -C $(BIN_DIR) $(APP_NAME)-darwin-amd64
41+
42+
# Mac Silicon (arm64)
43+
GOOS=darwin GOARCH=arm64 go build $(LDFLAGS) -o $(BIN_DIR)/$(APP_NAME)-darwin-arm64 $(SRC_DIR)
44+
tar -czvf $(BIN_DIR)/$(APP_NAME)-darwin-arm64.tar.gz -C $(BIN_DIR) $(APP_NAME)-darwin-arm64
45+
46+
# Build for the CURRENT OS (Local development)
47+
build-local:
48+
@echo "Building $(APP_NAME) for local OS..."
49+
@mkdir -p $(BIN_DIR)
50+
go build $(LDFLAGS) -o $(BIN_DIR)/$(APP_NAME) $(SRC_DIR)
51+
52+
# Clean up binaries
53+
clean:
54+
@echo "Cleaning up..."
55+
@rm -rf $(BIN_DIR)
56+
57+
# Run the tool locally
58+
run: build-local
59+
@./$(BIN_DIR)/$(APP_NAME) --help
60+
61+
# Show this help menu
62+
help:
63+
@echo "Makefile for $(APP_NAME)"
64+
@echo "Usage:"
65+
@echo " make build - Create .tar.gz releases for Linux (CentOS/Ubuntu) and Mac"
66+
@echo " make build-local - Build native binary for local testing"
67+
@echo " make clean - Remove build artifacts"
68+
@echo " make run - Build locally and run (shows help)"

0 commit comments

Comments
 (0)