Skip to content

Commit 1adda93

Browse files
committed
First commit
1 parent d7b5ad8 commit 1adda93

41 files changed

Lines changed: 3932 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/go.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: Go
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
branches: [ "main" ]
8+
9+
jobs:
10+
lint:
11+
strategy:
12+
matrix:
13+
go: [stable]
14+
os: [ubuntu-latest ] #, macos-latest—] #, windows-latest]
15+
name: lint
16+
runs-on: ${{ matrix.os }}
17+
steps:
18+
- name: Checkout code
19+
uses: actions/checkout@v4
20+
with:
21+
fetch-depth: 0
22+
- name: Set up Go
23+
uses: actions/setup-go@v5
24+
with:
25+
go-version: '1.24'
26+
- name: Build
27+
run: |
28+
make build
29+
- name: golangci-lint
30+
uses: golangci/golangci-lint-action@v6
31+
with:
32+
version: v1.64
33+
- name: Test
34+
run: make test
35+
release:
36+
needs: lint
37+
name: build package
38+
runs-on: ubuntu-latest
39+
steps:
40+
- name: Checkout code
41+
uses: actions/checkout@v4
42+
with:
43+
fetch-depth: 0
44+
- name: Set up Go
45+
uses: actions/setup-go@v5
46+
with:
47+
go-version: '1.24'
48+
- name: Set up GOPATH
49+
run: echo "GOPATH=$HOME/go" >> $GITHUB_ENV

.github/workflows/package.yaml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*.*.*'
7+
8+
permissions:
9+
contents: write
10+
11+
jobs:
12+
# lint:
13+
# strategy:
14+
# matrix:
15+
# go: [stable]
16+
# os: [ubuntu-latest] # , macos-latest, windows-latest]
17+
# name: lint
18+
# runs-on: ${{ matrix.os }}
19+
# steps:
20+
# - name: Checkout code
21+
# uses: actions/checkout@v4
22+
#
23+
# - name: Set up Go
24+
# uses: actions/setup-go@v5
25+
# with:
26+
# go-version: '1.24'
27+
# - name: Build
28+
# run: |
29+
# make build
30+
# - name: golangci-lint
31+
# uses: golangci/golangci-lint-action@v6
32+
# with:
33+
# version: v1.64
34+
# - name: Test
35+
# run: make test
36+
release:
37+
runs-on: ubuntu-latest
38+
steps:
39+
- uses: actions/checkout@v4
40+
- run: git fetch --prune --unshallow
41+
- uses: actions/setup-go@v5
42+
with:
43+
go-version: "1.24"
44+
- name: Set release version into env variable
45+
run: echo "RELEASE_TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
46+
- name: Set up GOPATH
47+
run: echo "GOPATH=$HOME/go" >> $GITHUB_ENV
48+
- name: Make and publish
49+
run: |
50+
make release
51+
env:
52+
GORELEASER_RELEASE: true
53+
GORELEASER_MOUNT_CONFIG: true
54+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,7 @@ go.work.sum
2323

2424
# env file
2525
.env
26+
# Added by goreleaser init:
27+
dist/
28+
29+
./ipdex

.goreleaser.yaml

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
before:
2+
hooks:
3+
- go mod tidy
4+
5+
env:
6+
- CGO_ENABLED=1
7+
builds:
8+
- id: ipdex-darwin-amd64
9+
binary: ipdex
10+
main: ./cmd/ipdex
11+
goarch:
12+
- amd64
13+
goos:
14+
- darwin
15+
env:
16+
- CC=o64-clang
17+
- CXX=o64-clang++
18+
flags:
19+
- -trimpath
20+
ldflags:
21+
- -X crowdsecurity/ipdex/pkg/version.Version={{ .Version }} -X crowdsecurity/ipdex/pkg/version.Version.Commit={{ .Commit }} -X crowdsecurity/ipdex/pkg/version.Version.BuildDate={{ .Date }}
22+
- id: ipdex-darwin-arm64
23+
binary: ipdex
24+
main: ./cmd/ipdex
25+
goarch:
26+
- arm64
27+
goos:
28+
- darwin
29+
env:
30+
- CC=oa64-clang
31+
- CXX=oa64-clang++
32+
flags:
33+
- -trimpath
34+
ldflags:
35+
- -X crowdsecurity/ipdex/pkg/version.Version={{ .Version }} -X crowdsecurity/ipdex/pkg/version.Version.Commit={{ .Commit }} -X crowdsecurity/ipdex/pkg/version.Version.BuildDate={{ .Date }}
36+
- id: ipdex-linux-amd64
37+
binary: ipdex
38+
main: ./cmd/ipdex
39+
env:
40+
- CC=x86_64-linux-gnu-gcc
41+
- CXX=x86_64-linux-gnu-g++
42+
goarch:
43+
- amd64
44+
goos:
45+
- linux
46+
flags:
47+
- -trimpath
48+
ldflags:
49+
- -extldflags "-lc -lrt -lpthread" -X crowdsecurity/ipdex/pkg/version.Version={{ .Version }} -X crowdsecurity/ipdex/pkg/version.Version.Commit={{ .Commit }} -X crowdsecurity/ipdex/pkg/version.Version.BuildDate={{ .Date }}
50+
- id: ipdex-linux-arm64
51+
binary: ipdex
52+
main: ./cmd/ipdex
53+
goarch:
54+
- arm64
55+
goos:
56+
- linux
57+
env:
58+
- CC=aarch64-linux-gnu-gcc
59+
- CXX=aarch64-linux-gnu-g++
60+
flags:
61+
- -trimpath
62+
ldflags:
63+
- -extldflags "-lc -lrt -lpthread" -X crowdsecurity/ipdex/pkg/version.Version={{ .Version }} -X crowdsecurity/ipdex/pkg/version.Version.Commit={{ .Commit }} -X crowdsecurity/ipdex/pkg/version.Version.BuildDate={{ .Date }}
64+
- id: ipdex-windows-amd64
65+
binary: ipdex
66+
main: ./cmd/ipdex
67+
goarch:
68+
- amd64
69+
goos:
70+
- windows
71+
env:
72+
- CC=x86_64-w64-mingw32-gcc
73+
- CXX=x86_64-w64-mingw32-g++
74+
flags:
75+
- -trimpath
76+
- -buildmode=exe
77+
ldflags:
78+
- -X crowdsecurity/ipdex/pkg/version.Version={{ .Version }} -X crowdsecurity/ipdex/pkg/version.Version.Commit={{ .Commit }} -X crowdsecurity/ipdex/pkg/version.Version.BuildDate={{ .Date }}
79+
80+
archives:
81+
- id: build binaries
82+
builds:
83+
- ipdex-darwin-amd64
84+
- ipdex-darwin-arm64
85+
- ipdex-linux-amd64
86+
- ipdex-linux-arm64
87+
- ipdex-windows-amd64
88+
name_template: "ipdex_{{ .Os }}_{{ .Arch }}"
89+
format: binary
90+
91+
release:
92+
footer: >-
93+
94+
---
95+
96+
Released by [GoReleaser](https://github.com/goreleaser/goreleaser).
97+
98+

Makefile

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Makefile for ipdex
2+
APP_NAME := ipdex
3+
CMD_DIR := ./cmd/$(APP_NAME)
4+
DIST_DIR := ./dist
5+
6+
GORELEASER_VERBOSE ?= false
7+
GORELEASER_IMAGE := ghcr.io/goreleaser/goreleaser-cross:v1.21.5
8+
GORELEASER_CONFIG ?= .goreleaser.yaml
9+
10+
GOOS_LIST := linux darwin windows
11+
GOARCH_LIST := amd64 arm64
12+
CGO_ENABLED := 1
13+
14+
GIT_COMMIT := $(shell git rev-parse --short HEAD)
15+
GIT_COMMIT_LONG := $(shell git rev-parse HEAD)
16+
GIT_TAG := $(shell git describe --tags --always)
17+
18+
GO_LINKMODE ?= external
19+
GO_MOD ?= readonly
20+
BUILD_TAGS ?= osusergo,netgo
21+
GO_LDFLAGS := -linkmode=$(GO_LINKMODE) \
22+
-X crowdsecurity/ipdex/pkg/version.Version=$(GIT_TAG) \
23+
-X crowdsecurity/ipdex/pkg/version.Version.Commit=$(GIT_COMMIT_LONG) \
24+
-X crowdsecurity/ipdex/pkg/version.Version.BuildDate=$(shell date -u +%Y-%m-%dT%H:%M:%SZ)
25+
26+
GO_BUILD_FLAGS := -mod=$(GO_MOD) -tags='$(BUILD_TAGS)' -ldflags '$(GO_LDFLAGS)'
27+
28+
.DEFAULT_GOAL := build
29+
30+
.PHONY: all build test clean release
31+
32+
all: clean build
33+
34+
build:
35+
go build $(GO_BUILD_FLAGS) -o ipdex ./cmd/ipdex
36+
37+
test:
38+
go test -v ./...
39+
40+
clean:
41+
rm -rf $(DIST_DIR)
42+
43+
release:
44+
@echo "Releasing with GoReleaser..."
45+
docker run \
46+
--rm \
47+
-e MOD="$(GO_MOD)" \
48+
-e BUILD_TAGS="$(BUILD_TAGS)" \
49+
-e LINKMODE="$(GO_LINKMODE)" \
50+
-e GITHUB_TOKEN="$(GITHUB_TOKEN)" \
51+
-e GORELEASER_CURRENT_TAG="$(RELEASE_TAG)" \
52+
-e GOPATH=/go \
53+
-v /var/run/docker.sock:/var/run/docker.sock \
54+
-v $(GOPATH):/go \
55+
-v $(PWD):/go/src/$(GO_MOD_NAME) \
56+
-w /go/src/$(GO_MOD_NAME) \
57+
$(GORELEASER_IMAGE) \
58+
-f "$(GORELEASER_CONFIG)" \
59+
release \
60+
--verbose=$(GORELEASER_VERBOSE) \
61+
--clean \

0 commit comments

Comments
 (0)