Skip to content

Commit

Permalink
First implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
igolaizola committed Apr 23, 2023
1 parent 8ab738a commit b4e50d9
Show file tree
Hide file tree
Showing 30 changed files with 4,425 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
github: igolaizola
custom: ["https://ko-fi.com/igolaizola", "https://buymeacoffee.com/igolaizola", "https://paypal.me/igolaizola"]
29 changes: 29 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: goreleaser

on:
push:
tags:
- '*'

permissions:
contents: write

jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- run: git fetch --force --tags
- uses: actions/setup-go@v3
with:
go-version-file: 'go.mod'
cache: true
- uses: goreleaser/goreleaser-action@v4
with:
distribution: goreleaser
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*.dll
*.so
*.dylib
bin

# Test binary, built with `go test -c`
*.test
Expand All @@ -13,3 +14,11 @@

# Dependency directories (remove the comment below to include it)
# vendor/

# Other
.history
.vscode
*.conf
*.yaml
output
logs
13 changes: 13 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
builds:
- binary: igogpt
main: ./cmd/igogpt
goarch:
- "386"
- amd64
- arm64
- arm
goarm:
- "6"
- "7"
archives:
- format: zip
15 changes: 15 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# builder image
FROM golang:alpine as builder
ARG TARGETPLATFORM
COPY . /src
WORKDIR /src
RUN apk add --no-cache make bash git
RUN make app-build PLATFORMS=$TARGETPLATFORM

# running image
FROM alpine
WORKDIR /home
COPY --from=builder /src/bin/igogpt-* /bin/igogpt

# executable
ENTRYPOINT [ "/bin/igogpt" ]
73 changes: 73 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#!/bin/bash

SHELL = /bin/bash
PLATFORMS ?= linux/amd64 darwin/amd64 windows/amd64
IMAGE_PREFIX ?= igolaizola
REPO_NAME ?= igogpt
COMMIT_SHORT ?= $(shell git rev-parse --verify --short HEAD)
VERSION ?= $(COMMIT_SHORT)
VERSION_NOPREFIX ?= $(shell echo $(VERSION) | sed -e 's/^[[v]]*//')

# Build the binaries for the current platform
.PHONY: build
build:
os=$$(go env GOOS); \
arch=$$(go env GOARCH); \
PLATFORMS="$$os/$$arch" make app-build

# Build the binaries
# Example: PLATFORMS=linux/amd64 make app-build
.PHONY: app-build
app-build:
@for platform in $(PLATFORMS) ; do \
os=$$(echo $$platform | cut -f1 -d/); \
arch=$$(echo $$platform | cut -f2 -d/); \
arm=$$(echo $$platform | cut -f3 -d/); \
arm=$${arm#v}; \
ext=""; \
if [ "$$os" == "windows" ]; then \
ext=".exe"; \
fi; \
file=./bin/$(REPO_NAME)-$(VERSION_NOPREFIX)-$$(echo $$platform | tr / -)$$ext; \
GOOS=$$os GOARCH=$$arch GOARM=$$arm CGO_ENABLED=0 \
go build \
-a -x -tags netgo,timetzdata -installsuffix cgo -installsuffix netgo \
-ldflags " \
-X main.Version=$(VERSION_NOPREFIX) \
-X main.GitRev=$(COMMIT_SHORT) \
" \
-o $$file \
./cmd/$(REPO_NAME); \
if [ $$? -ne 0 ]; then \
exit 1; \
fi; \
chmod +x $$file; \
done

# Build the docker image
# Example: PLATFORMS=linux/amd64 make docker-build
.PHONY: docker-build
docker-build:
@platforms=($(PLATFORMS)); \
platform=$${platforms[0]}; \
if [[ $${#platforms[@]} -ne 1 ]]; then \
echo "Multi-arch build not supported"; \
exit 1; \
fi; \
docker build --platform $$platform -t $(IMAGE_PREFIX)/$(REPO_NAME):$(VERSION) .; \
if [ $$? -ne 0 ]; then \
exit 1; \
fi

# Build the docker images using buildx
# Example: PLATFORMS="linux/amd64 darwin/amd64 windows/amd64" make docker-buildx
.PHONY: docker-buildx
docker-buildx:
@platforms=($(PLATFORMS)); \
platform=$$(IFS=, ; echo "$${platforms[*]}"); \
docker buildx build --platform $$platform -t $(IMAGE_PREFIX)/$(REPO_NAME):$(VERSION) .

# Clean binaries
.PHONY: clean
clean:
rm -rf bin
Loading

0 comments on commit b4e50d9

Please sign in to comment.