Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 100 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
name: CI

on:
push:
branches: [ master, main ]
pull_request:
branches: [ master, main ]

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
go-version: [1.21, 1.22]

steps:
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go-version }}

- name: Cache Go modules
uses: actions/cache@v3
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-

- name: Verify Go modules
run: go version && go mod verify

- name: Install dependencies
run: go mod download

- name: Run golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: latest

- name: Run tests
run: make -f Makefile_go test

- name: Run integration tests
run: make -f Makefile_go integration-test

- name: Build
run: make -f Makefile_go build

- name: Run e2e tests
run: make -f Makefile_go e2e-test

- name: Generate coverage report
run: make -f Makefile_go coverage

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
file: ./coverage.out

build:
runs-on: ubuntu-latest
needs: test

steps:
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.22

- name: Build for multiple platforms
run: make -f Makefile_go build-all

- name: Upload build artifacts
uses: actions/upload-artifact@v3
with:
name: binaries
path: build/bin/

docker:
runs-on: ubuntu-latest
needs: test

steps:
- uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build Docker image
run: make -f Makefile_go docker-build

- name: Test Docker image
run: |
docker run --rm flare-tools:$(git describe --tags --dirty --always) flare-admin --help
docker run --rm flare-tools:$(git describe --tags --dirty --always) flare-stats --help
73 changes: 73 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: Release

on:
push:
tags:
- 'v*'

jobs:
release:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.21

- name: Get tag name
id: tag
run: echo "TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT

- name: Build for multiple platforms
run: make build-all

- name: Create release archives
run: |
cd build/bin
tar -czf flare-tools-${{ steps.tag.outputs.TAG }}-linux-amd64.tar.gz linux-amd64/
tar -czf flare-tools-${{ steps.tag.outputs.TAG }}-darwin-amd64.tar.gz darwin-amd64/
zip -r flare-tools-${{ steps.tag.outputs.TAG }}-windows-amd64.zip windows-amd64/

- name: Create Release
uses: actions/create-release@v1
id: create_release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.tag.outputs.TAG }}
release_name: Release ${{ steps.tag.outputs.TAG }}
draft: false
prerelease: false

- name: Upload Linux Release Asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./build/bin/flare-tools-${{ steps.tag.outputs.TAG }}-linux-amd64.tar.gz
asset_name: flare-tools-${{ steps.tag.outputs.TAG }}-linux-amd64.tar.gz
asset_content_type: application/gzip

- name: Upload Darwin Release Asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./build/bin/flare-tools-${{ steps.tag.outputs.TAG }}-darwin-amd64.tar.gz
asset_name: flare-tools-${{ steps.tag.outputs.TAG }}-darwin-amd64.tar.gz
asset_content_type: application/gzip

- name: Upload Windows Release Asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./build/bin/flare-tools-${{ steps.tag.outputs.TAG }}-windows-amd64.zip
asset_name: flare-tools-${{ steps.tag.outputs.TAG }}-windows-amd64.zip
asset_content_type: application/zip
71 changes: 71 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
run:
timeout: 5m
issues-exit-code: 1
tests: true

linters:
enable:
- gofmt
- govet
- errcheck
- unused
- ineffassign
- typecheck
- goimports
- misspell
- staticcheck
- gosimple
- stylecheck

linters-settings:
gocyclo:
min-complexity: 15
gocognit:
min-complexity: 20
dupl:
threshold: 100
goconst:
min-len: 3
min-occurrences: 3
misspell:
locale: US
lll:
line-length: 120
goimports:
local-prefixes: github.com/gree/flare-tools
govet:
enable:
- shadow # replaces check-shadowing
maligned:
suggest-new: true
gocritic:
enabled-tags:
- diagnostic
- experimental
- opinionated
- performance
- style
disabled-checks:
- dupImport
- ifElseChain
- octalLiteral
- whyNoLint
- wrapperFunc

issues:
exclude-rules:
- path: _test\.go
linters:
- errcheck
- path: test/
linters:
- errcheck
- path: cmd/
linters:
- errcheck
- text: "Error return value of.*is not checked"
linters:
- errcheck
- text: "should have comment or be unexported"
linters:
- revive
46 changes: 46 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Multi-stage build for flare-tools
FROM golang:1.21-alpine AS builder

# Install build dependencies
RUN apk add --no-cache git make

# Set working directory
WORKDIR /app

# Copy go mod files
COPY go.mod go.sum ./

# Download dependencies
RUN go mod download

# Copy source code
COPY . .

# Build binaries
RUN make build

# Final stage
FROM alpine:latest

# Install runtime dependencies
RUN apk add --no-cache ca-certificates

# Create non-root user
RUN addgroup -g 1001 flare && \
adduser -D -s /bin/sh -u 1001 -G flare flare

# Set working directory
WORKDIR /home/flare

# Copy binaries from builder stage
COPY --from=builder /app/build/bin/flare-admin /usr/local/bin/
COPY --from=builder /app/build/bin/flare-stats /usr/local/bin/

# Change ownership
RUN chown -R flare:flare /home/flare

# Switch to non-root user
USER flare

# Set default command
CMD ["flare-admin", "--help"]
25 changes: 25 additions & 0 deletions Dockerfile.debian
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
FROM --platform=linux/amd64 ubuntu:noble

# Install build dependencies
RUN apt-get update && apt-get install -y \
build-essential \
debhelper \
golang-go \
git \
&& rm -rf /var/lib/apt/lists/*

# Set Go environment
ENV GOPATH=/go
ENV PATH=$GOPATH/bin:/usr/local/go/bin:$PATH

# Create working directory
WORKDIR /build

# Copy source code
COPY . .

# Build the debian package
RUN dpkg-buildpackage -us -uc -b

# List generated files
RUN ls -la /
Loading
Loading