Skip to content

Commit

Permalink
feat: Initial Release (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulojmdias authored Oct 14, 2024
2 parents 6c45f8f + 3b45798 commit 5e2b10d
Show file tree
Hide file tree
Showing 26 changed files with 2,935 additions and 0 deletions.
77 changes: 77 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: CI/CD with Tests, Semantic Release, GoReleaser and Docker Build

on:
push:
branches:
- main

jobs:
tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: "1.23"
- name: install
run: |
go install -v golang.org/x/tools/cmd/goimports@latest
go install -v honnef.co/go/tools/cmd/staticcheck@latest
- name: Test
run: |
make fmt && git diff --exit-code
make imports && git diff --exit-code
make test
semantic_release:
name: Semantic Release
runs-on: ubuntu-latest
needs: tests
outputs:
version: ${{ steps.get-version.outputs.version }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
persist-credentials: false
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: "1.23"
- name: Install GoReleaser
run: go install github.com/goreleaser/goreleaser/v2@latest
- name: Semantic Release
uses: cycjimmy/semantic-release-action@v4
with:
extra_plugins: |
@semantic-release/exec
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
- id: get-version
run: echo "VERSION=$(cat VERSION)" >> $GITHUB_OUTPUT
docker_build:
name: Docker build
runs-on: ubuntu-latest
needs: semantic_release
steps:
- uses: actions/checkout@v2
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: "${{ secrets.DOCKERIO_USERNAME }}"
password: "${{ secrets.DOCKERIO_TOKEN }}"
- name: Build and push
uses: docker/build-push-action@v6
with:
platforms: linux/amd64,linux/arm64
push: true
tags: |
lokxy/lokxy:${{ github.ref_name == 'main' && 'latest' || github.ref_name }},lokxy/lokxy:${{ needs.semantic_release.outputs.version }}
cache-from: type=registry,ref=lokxy/lokxy:latest
cache-to: type=registry,ref=lokxy/lokxy:latest,mode=max,image-manifest=true
env:
LOKXY_VERSION: ${{ needs.semantic_release.outputs.version }}
25 changes: 25 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Tests

on:
pull_request:
branches:
- main

jobs:
tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: "1.23"
- name: install
run: |
go install -v golang.org/x/tools/cmd/goimports@latest
go install -v honnef.co/go/tools/cmd/staticcheck@latest
- name: Test
run: |
make fmt && git diff --exit-code
make imports && git diff --exit-code
make test
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*.dll
*.so
*.dylib
lokxy

# Test binary, built with `go test -c`
*.test
Expand All @@ -23,3 +24,4 @@ go.work.sum

# env file
.env
config.yaml
52 changes: 52 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
version: 2
project_name: lokxy

env:
- GO111MODULE=on
- CGO_ENABLED=0

before:
hooks:
- go mod tidy
- go mod download

metadata:
mod_timestamp: "{{ .CommitTimestamp }}"

report_sizes: true

archives:
- format: tar.gz
files:
- LICENSE

builds:
- main: ./cmd/
binary: lokxy
env:
- CGO_ENABLED=0
goos:
- linux
- darwin
- windows
goarch:
- "386"
- amd64
- arm
- arm64
- ppc64
goarm:
- "7"
ignore:
- goos: windows
goarch: arm
- goos: darwin
goarch: "386"
- goos: linux
goarch: arm
goarm: 7
mod_timestamp: "{{ .CommitTimestamp }}"
flags:
- -trimpath
ldflags:
- -s -w -X main.version={{ .Env.GORELEASER_CURRENT_TAG }} -X main.commit={{ .Commit }} -X main.date={{ .CommitDate }} -X main.builtBy=goreleaser
16 changes: 16 additions & 0 deletions .releaserc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
branches:
- main

plugins:
- "@semantic-release/commit-analyzer"
- "@semantic-release/release-notes-generator"
- - "@semantic-release/exec"
- prepareCmd: 'echo "${nextRelease.version}" >> VERSION'
publishCmd: |
echo "${nextRelease.notes}" > /tmp/release-notes.md
export GORELEASER_CURRENT_TAG=$(cat VERSION)
goreleaser release --release-notes /tmp/release-notes.md --clean --skip=validate
- "@semantic-release/changelog"
- "@semantic-release/git"

tagFormat: ${version}
21 changes: 21 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM debian:12-slim AS builder

ARG BUILDPLATFORM
ARG TARGETARCH
ARG TARGETOS
ARG LOKXY_VERSION
ENV GOARCH=${TARGETARCH} GOOS=${TARGETOS}

RUN apt update &&\
apt install -y --no-install-recommends --no-install-suggests \
curl &&\
curl -sL -o /tmp/lokxy_${LOKXY_VERSION}_${TARGETOS}_${TARGETARCH}.tar.gz https://github.com/paulojmdias/lokxy/releases/download/${LOKXY_VERSION}/lokxy_${LOKXY_VERSION}_${TARGETOS}_${TARGETARCH}.tar.gz &&\
tar -xvf /tmp/lokxy_${LOKXY_VERSION}_${TARGETOS}_${TARGETARCH}.tar.gz -C /tmp

FROM gcr.io/distroless/static-debian12

EXPOSE 3100

COPY --from=builder /tmp/lokxy /usr/local/bin/lokxy

CMD ["/usr/local/bin/lokxy"]
18 changes: 18 additions & 0 deletions Dockerfile.local
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM golang:1.23 AS builder

ARG BUILDPLATFORM
ARG TARGETARCH
ARG TARGETOS
ENV GOARCH=${TARGETARCH} GOOS=${TARGETOS}

COPY . /go/src/github.com/paulojmdias/lokxy
RUN cd /go/src/github.com/paulojmdias/lokxy &&\
make build

FROM gcr.io/distroless/static-debian12

EXPOSE 3100

COPY --from=builder /go/src/github.com/paulojmdias/lokxy/lokxy /usr/local/bin/lokxy

CMD ["/usr/local/bin/lokxy"]
34 changes: 34 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
BUILD := build
GO ?= go
GOFILES := $(shell find . -name "*.go" -type f ! -path "./vendor/*")
GOFMT ?= gofmt
GOIMPORTS ?= goimports -local=github.com/paulojmdias/lokxy
STATICCHECK ?= staticcheck

.PHONY: clean
clean:
$(GO) clean -i ./...
rm -rf $(BUILD)

.PHONY: static-check
static-check:
$(STATICCHECK) ./...

.PHONY: fmt
fmt:
$(GOFMT) -w -s $(GOFILES)

.PHONY: imports
imports:
$(GOIMPORTS) -w $(GOFILES)

.PHONY: test
test:
GO111MODULE=on $(GO) test -race -mod=mod -tags netgo,builtinassets ./...

.PHONY: build
build:
CGO_ENABLED=0 go build -mod=mod -tags netgo,builtinassets -x -o lokxy ./cmd/

testlocal-build:
docker build -f Dockerfile.local --load -t lokxy:latest .
Loading

0 comments on commit 5e2b10d

Please sign in to comment.