8 Commits

Author SHA1 Message Date
Bo-Yi Wu
79e439dbc7 ci: update goreleaser action and version specification
- Update `goreleaser` action from v5 to v6
- Change `goreleaser` version specification to `~> v2`

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2024-06-11 11:20:41 +08:00
Bo-Yi Wu
a4b8f12321 chore: refactor changelog management and configuration
- Remove the `project_name` field
- Change changelog source from `git` to `gitea`
- Add new changelog categories for refactor, build process updates, and documentation updates
- Remove the changelog order and filters configuration

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2024-06-11 11:19:00 +08:00
Bo-Yi Wu
058d36bc64 ci: enhance CI Workflow and Update Ignore Rules
- Add a new 'testing' job to the Gitea workflow with steps for checkout, setup Go, caching, building, and testing
- Include 'bin' directory in the .gitignore file

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2024-02-20 09:54:17 +08:00
Bo-Yi Wu
f171daa81a feat: implement example-go service with Docker support
- Add a new Makefile with build, docker-build, test, and clean targets, including cross-compilation support for Linux AMD64 and ARM64.
- Introduce a new Go executable `example-go` with a basic HTTP server setup.
- Create a new Dockerfile for an Alpine-based container including the `example-go` binary, with metadata labels and an entrypoint.

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2024-02-20 09:51:50 +08:00
Bo-Yi Wu
9d1d40c08a chore: refactor build process and repository cleanup
- Introduce Go setup and caching in Docker GitHub Actions workflow
- Add `release` directory to `.gitignore`
- Remove `main.go` file from the repository

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2024-02-20 09:51:29 +08:00
Bo-Yi Wu
0d1a3ae368 ci: implement Docker image CI/CD workflow
- Add a new GitHub Actions workflow for Docker image creation and push
- Trigger the workflow on push to main branch and tags starting with 'v'
- Trigger the workflow on pull requests to the main branch
- Define environment variable `BUILDKIT_NO_CLIENT_TOKEN`
- Set up the workflow to run on `ubuntu-latest` with a specific container image
- Include steps for checking out the code, setting up QEMU, and Docker Buildx
- Configure Docker Buildx with debug mode and insecure entitlements
- Add steps to log in to Docker Hub using secrets for username and password
- Generate Docker image tags based on semantic versioning and push conditionally on event type
- Build and push Docker image specifying the platform, Dockerfile location, and tag and label metadata
- Disable provenance and SBOM (Software Bill of Materials) generation in the build-push action

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2024-02-20 09:43:08 +08:00
Bo-Yi Wu
bf749b4823 ci: update testing workflow for Go version consistency
- Correct the `go-version-file` syntax by removing quotes in the testing workflow
- Add `check-latest` flag to ensure the latest Go version is used in testing workflow

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2024-02-19 10:24:03 +08:00
Bo-Yi Wu
082886c85b ci: update Gitea release workflow Go version management
- Use `go.mod` to determine Go version in Gitea release workflow
- Ensure the latest Go version is used in Gitea release workflow

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2024-02-19 10:23:43 +08:00
8 changed files with 257 additions and 18 deletions

View File

@@ -0,0 +1,99 @@
name: Docker Image
on:
push:
branches:
- main
tags:
- "v*"
pull_request:
branches:
- "main"
env:
BUILDKIT_NO_CLIENT_TOKEN: 1
jobs:
build-docker:
runs-on: ubuntu-latest
container:
image: catthehacker/ubuntu:act-20.04
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0 # all history for all branches and tags
- uses: actions/setup-go@v5
with:
go-version-file: go.mod
check-latest: true
- uses: https://gitea.com/actions/go-hashfiles@v0.0.1
id: hash-go
with:
patterns: |
go.mod
go.sum
- name: cache go
id: cache-go
uses: https://github.com/actions/cache@v3
with:
path: |
/go_path
/go_cache
key: go_path-${{ steps.hash-go.outputs.hash }
- name: Build binary
env:
TAGS: ""
run: |
make docker-build-linux-amd64
make docker-build-linux-arm64
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Setup docker context for buildx
id: buildx-context
run: docker context create builders || docker context use builders
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
with:
endpoint: builders
config-inline: |
debug = true
insecure-entitlements = [ "network.host", "security.insecure" ]
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Docker meta
id: docker-meta
uses: docker/metadata-action@v5
with:
images: |
gitea/example-go
tags: |
type=raw,value=latest,enable={{is_default_branch}}
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
- name: Build and push
uses: docker/build-push-action@v4
env:
ACTIONS_RUNTIME_TOKEN: ""
with:
context: .
platforms: linux/amd64
file: docker/Dockerfile
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.docker-meta.outputs.tags }}
labels: ${{ steps.docker-meta.outputs.labels }}
provenance: false
sbom: false

View File

@@ -22,7 +22,8 @@ jobs:
- uses: actions/setup-go@v5
with:
go-version: "^1"
go-version-file: go.mod
check-latest: true
- uses: https://gitea.com/actions/go-hashfiles@v0.0.1
id: hash-go
with:
@@ -39,11 +40,11 @@ jobs:
key: go_path-${{ steps.hash-go.outputs.hash }
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v5
uses: goreleaser/goreleaser-action@v6
with:
# either 'goreleaser' (default) or 'goreleaser-pro'
distribution: goreleaser
version: latest
version: "~> v2"
args: release --clean
env:
GITEA_TOKEN: ${{ secrets.GITHUB_TOKEN }}

View File

@@ -17,7 +17,8 @@ jobs:
fetch-depth: 0 # all history for all branches and tags
- uses: actions/setup-go@v5
with:
go-version-file: "go.mod"
go-version-file: go.mod
check-latest: true
- uses: https://gitea.com/actions/go-hashfiles@v0.0.1
id: hash-go
with:
@@ -37,3 +38,35 @@ jobs:
with:
version: v1.56.2
args: --timeout 5m
testing:
name: check and test
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0 # all history for all branches and tags
- name: Setup go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
check-latest: true
- uses: https://gitea.com/actions/go-hashfiles@v0.0.1
id: hash-go
with:
patterns: |
go.mod
go.sum
- name: cache go
id: cache-go
uses: actions/cache@v4
with:
path: |
/go_path
/go_cache
key: go_path-${{ steps.hash-go.outputs.hash }}
- name: build
run: make build
- name: test
run: make test

3
.gitignore vendored
View File

@@ -20,4 +20,5 @@
# Go workspace file
go.work
release
bin

View File

@@ -1,5 +1,3 @@
project_name: go
builds:
- # If true, skip the build.
# Useful for library projects.
@@ -20,7 +18,7 @@ changelog:
# - `github-native`: uses the GitHub release notes generation API, disables the groups feature.
#
# Defaults to `git`.
use: git
use: gitea
# Sorts the changelog by the commit's messages.
# Could either be asc, desc or empty
@@ -43,17 +41,16 @@ changelog:
- title: "Enhancements"
regexp: "^.*chore[(\\w)]*:+.*$"
order: 2
- title: "Refactor"
regexp: "^.*refactor[(\\w)]*:+.*$"
order: 3
- title: "Build process updates"
regexp: ^.*?(build|ci)(\(.+\))??!?:.+$
order: 4
- title: "Documentation updates"
regexp: ^.*?docs?(\(.+\))??!?:.+$
order: 4
- title: Others
order: 999
filters:
# Commit messages matching the regexp listed here will be removed from
# the changelog
# Default is empty
exclude:
- "^docs"
- "CICD"
- typo
gitea_urls:
api: https://gitea.com/api/v1

87
Makefile Normal file
View File

@@ -0,0 +1,87 @@
EXECUTABLE ?= example-go
SOURCES ?= $(shell find . -name "*.go" -type f)
DIST := dist
DIST_DIRS := $(DIST)/binaries $(DIST)/release
GO ?= go
TAGS ?=
HAS_GO = $(shell hash $(GO) > /dev/null 2>&1 && echo "GO" || echo "NOGO" )
ifneq ($(shell uname), Darwin)
EXTLDFLAGS = -extldflags "-static" $(null)
else
EXTLDFLAGS =
endif
ifeq ($(HAS_GO), GO)
GOPATH ?= $(shell $(GO) env GOPATH)
export PATH := $(GOPATH)/bin:$(PATH)
CGO_EXTRA_CFLAGS := -DSQLITE_MAX_VARIABLE_NUMBER=32766
CGO_CFLAGS ?= $(shell $(GO) env CGO_CFLAGS) $(CGO_EXTRA_CFLAGS)
endif
ifeq ($(OS), Windows_NT)
GOFLAGS := -v -buildmode=exe
EXECUTABLE ?= $(EXECUTABLE).exe
else ifeq ($(OS), Windows)
GOFLAGS := -v -buildmode=exe
EXECUTABLE ?= $(EXECUTABLE).exe
else
GOFLAGS := -v
EXECUTABLE ?= $(EXECUTABLE)
endif
STORED_VERSION_FILE := VERSION
ifneq ($(DRONE_TAG),)
VERSION ?= $(subst v,,$(DRONE_TAG))
RELASE_VERSION ?= $(VERSION)
else
ifneq ($(DRONE_BRANCH),)
VERSION ?= $(subst release/v,,$(DRONE_BRANCH))
else
VERSION ?= main
endif
STORED_VERSION=$(shell cat $(STORED_VERSION_FILE) 2>/dev/null)
ifneq ($(STORED_VERSION),)
RELASE_VERSION ?= $(STORED_VERSION)
else
RELASE_VERSION ?= $(shell git describe --tags --always | sed 's/-/+/' | sed 's/^v//')
endif
endif
LDFLAGS ?= -X 'main.Version=$(RELASE_VERSION)'
build: $(EXECUTABLE)
$(EXECUTABLE): $(SOURCES)
$(GO) build -v -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' -o bin/$@ ./cmd/$(EXECUTABLE)
docker-build: docker-build-linux-amd64 docker-build-linux-arm64
docker-build-linux-amd64:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GO) build -v -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' -o release/linux/amd64/$(EXECUTABLE) ./cmd/$(EXECUTABLE)
docker-build-linux-arm64:
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 $(GO) build -v -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' -o release/linux/arm64/$(EXECUTABLE) ./cmd/$(EXECUTABLE)
test:
@$(GO) test -cover -tags '$(TAGS)' ./... && echo "\n==>\033[32m Ok\033[m\n" || exit 1
# install air command
.PHONY: air
air:
@hash air > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
$(GO) install github.com/cosmtrek/air@latest; \
fi
# run air
.PHONY: dev
dev: air
air --build.cmd "make build" --build.bin bin/$(EXECUTABLE)
.PHONY: release-clean
release-clean:
rm -rf $(DIST)
clean: release-clean

21
docker/Dockerfile Normal file
View File

@@ -0,0 +1,21 @@
FROM alpine:3.19
ARG TARGETOS
ARG TARGETARCH
LABEL maintainer="Bo-Yi Wu <appleboy.tw@gmail.com>" \
org.label-schema.name="api" \
org.label-schema.vendor="Bo-Yi Wu" \
org.label-schema.schema-version="1.0" \
com.centurylinklabs.watchtower.stop-signal="SIGINT" \
io.containers.autoupdate="registry"
RUN apk update && apk add --no-cache ca-certificates
EXPOSE 8080
ENV GODEBUG netdns=go
COPY release/${TARGETOS}/${TARGETARCH}/example-go /bin/example-go
ENTRYPOINT ["/bin/example-go"]