Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
wbollock authored Dec 18, 2023
0 parents commit e36f64c
Show file tree
Hide file tree
Showing 8 changed files with 333 additions and 0 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/golang-tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Go Test

on:
push:
tags:
- v*
branches: [main]
pull_request:

permissions:
contents: read

jobs:
build-and-test:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: '1.21'

- name: Install dependencies
run: go mod download

- name: Run tests
run: go test -v ./...
23 changes: 23 additions & 0 deletions .github/workflows/golangci-lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: golangci-lint
on:
push:
tags:
- v*
branches:
- main
pull_request:

permissions:
contents: read

jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v3
with:
go-version: 1.21
- uses: actions/checkout@v3
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
27 changes: 27 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# If you prefer the allow list template instead of the deny list, see community template:
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
#
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# go_project_template binary
go_project_template

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

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

# Go workspace file
go.work

# goreleaser
dist/
105 changes: 105 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
# Make sure to check the documentation at https://goreleaser.com
before:
hooks:
- go mod tidy
- go test -v ./...
builds:
- env:
- CGO_ENABLED=0
goos:
- linux
- windows
- darwin
goarch:
- amd64
- arm64
ldflags:
- -X main.Version={{.Version}} -X main.Commit={{.Commit}} -X main.BuildDate={{ .CommitDate }}
main: ./cmd/main.go
archives:
- name_template: >-
{{ .ProjectName }}_
{{- title .Os }}_
{{- if eq .Arch "amd64" }}x86_64
{{- else if eq .Arch "386" }}i386
{{- else if eq .Arch "darwin" }}Darwin
{{- else if eq .Arch "linux" }}Linux
{{- else if eq .Arch "windows" }}Windows
{{- else }}{{ .Arch }}{{ end }}
checksum:
name_template: 'checksums.txt'
snapshot:
name_template: "{{ incpatch .Version }}-next"
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
dockers:
# build latest and specific tag version images
# https://goreleaser.com/cookbooks/multi-platform-docker-images/#other-things-to-pay-attention-to
- image_templates:
- "ghcr.io/linode-obs/{{.ProjectName}}:{{ .Tag }}"
- "ghcr.io/linode-obs/{{.ProjectName}}:{{ .Tag }}-amd64"
- "ghcr.io/linode-obs/{{.ProjectName}}:latest" # keep latest as linux/amd64
use: buildx
goos: linux
goarch: amd64
build_flag_templates:
- "--pull"
- "--label=org.opencontainers.image.created={{.Date}}"
- "--label=org.opencontainers.image.title={{.ProjectName}}"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
- "--label=org.opencontainers.image.version={{.Version}}"
- "--label=org.opencontainers.image.source=https://github.com/linode-obs/go_project_template"
- "--label=org.opencontainers.image.description='go_project_template description TODO'"
- "--label=org.opencontainers.image.licenses=MIT"
- "--platform=linux/amd64"
dockerfile: "Dockerfile"
- image_templates:
- "ghcr.io/linode-obs/{{.ProjectName}}:{{ .Tag }}-linux-arm64"
use: buildx
goos: linux
goarch: arm64
build_flag_templates:
- "--pull"
- "--label=org.opencontainers.image.created={{.Date}}"
- "--label=org.opencontainers.image.title={{.ProjectName}}"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
- "--label=org.opencontainers.image.version={{.Version}}"
- "--label=org.opencontainers.image.source=https://github.com/linode-obs/go_project_template"
- "--label=org.opencontainers.image.description='go_project_template description TODO'"
- "--label=org.opencontainers.image.licenses=MIT"
- "--platform=linux/arm64"
dockerfile: "Dockerfile"
nfpms:
- id: default
formats:
- deb
- rpm
package_name: "go_project_template"
section: "default"
priority: "extra"
replaces: []
dependencies: []
recommends: []
suggests: []
conflicts: []
maintainer: "Will Bollock <linode-obs@gmail.com>"
description: |
go_project_template description TODO
homepage: "https://github.com/linode-obs/go_project_template"
license: "MIT"
contents:
# provided by goreleaser
- src: ./dist/go_project_template_linux_amd64_v1/go_project_template
dst: /usr/local/bin/go_project_template
- src: ./nfpm/systemd/go_project_template.service
dst: /etc/systemd/system/go_project_template.service
type: config
- src: ./nfpm/etc/default/go_project_template
dst: /etc/default/go_project_template
type: config
scripts:
postinstall: ./nfpm/scripts/postinstall.sh
36 changes: 36 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
repos:
- repo: https://github.com/tekwizely/pre-commit-golang
rev: v1.0.0-rc.1
hooks:
#
# Go Build
#
- id: go-build-mod
- id: go-build-repo-mod
#
# Go Mod Tidy
#
- id: go-mod-tidy
- id: go-mod-tidy-repo
#
# Go Test
#
- id: go-test-mod
- id: go-test-repo-mod
#
# Formatters
#
- id: go-fmt
- id: go-fmt-repo
#
#
# GolangCI-Lint
# - Fast Multi-Linter
# - Can be configured to replace MOST other hooks
# - Supports repo config file for configuration
# - https://github.com/golangci/golangci-lint
#
- id: golangci-lint
- id: golangci-lint-mod
- id: golangci-lint-repo-mod

17 changes: 17 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
ARG ARCH="amd64"
ARG OS="linux"
FROM golang:alpine3.18 AS builderimage
LABEL maintainer="Akamai SRE Observability Team <support@linode.com>"
WORKDIR /go/src/go_project_template
COPY . .
RUN go build -o go_project_template cmd/main.go

###################################################################

FROM golang:alpine3.18
COPY --from=builderimage /go/src/go_project_template/go_project_template /app/
WORKDIR /app

EXPOSE 9141
USER nobody
ENTRYPOINT [ "./go_project_template" ]
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Linode Observability Team

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
74 changes: 74 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
This is an opinionated Golang project template skeleton. Replace linode-obs/go_project_template with your project. Sometimes just go_project_template will need to be replaced. Also search TODO.

Make sure to write tests and `pre-commit install`. You'll also want to install [goreleaser](https://goreleaser.com/) and [pre-commit](https://pre-commit.com/). Note that the MIT license is included too.

Beware that:

* The Go version is set at `1.21` in [golang-tests.yaml](.github/workflows/golang-tests.yaml). This could be automated with renovate or dependabot
* Markdown table of contents be nice to add, easy to create with an [extension](https://marketplace.visualstudio.com/items?itemName=yzhang.markdown-all-in-one) in your editor of choice
* Document your CLI values and metrics instrumented

# go_project_template

![Github Release Downloads](https://img.shields.io/github/downloads/linode-obs/go_project_template/total.svg)
[![license](https://img.shields.io/badge/License-MIT-blue.svg)](https://github.com/linode-obs/go_project_template/blob/master/LICENSE)
[![golangci-lint](https://github.com/linode-obs/go_project_template/actions/workflows/golangci-lint.yaml/badge.svg)](https://github.com/linode-obs/go_project_template/actions/workflows/golangci-lint.yaml)
![Go Report Card](https://goreportcard.com/badge/github.com/linode-obs/go_project_template)
[![contributions](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat")](https://github.com/linode-obs/go_project_template/issues)

Project description.

We recommend using a standard [go project layout](https://github.com/golang-standards/project-layout) too.

Features:

* Feature 1
* Feature 2

## Installation

### Debian/RPM package

Substitute `{{ version }}` for your desired release.

```bash
wget https://github.com/linode-obs/go_project_template/releases/download/v{{ version }}/go_project_template_{{ version }}_linux_amd64.{deb,rpm}
{dpkg,rpm} -i go_project_template_{{ version }}_linux_amd64.{deb,rpm}
```

### Docker

```console
sudo docker run \
--privileged \
ghcr.io/linode-obs/go_project_template
```

### Binary

```bash
wget https://github.com/linode-obs/go_project_template/releases/download/v{{ version }}/go_project_template_{{ version }}_Linux_x86_64.tar.gz
tar xvf go_project_template_{{ version }}_Linux_x86_64.tar.gz
./go_project_template/go_project_template
```

### Source

```bash
wget https://github.com/linode-obs/go_project_template/archive/refs/tags/v{{ version }}.tar.gz
tar xvf go_project_template-{{ version }}.tar.gz
cd ./go_project_template-{{ version }}
go build go_project_template.go
./go_project_template.go
```

## Releasing

1. Merge commits to main.
2. Tag release `git tag -a v1.0.X -m "message"`
3. `git push origin v1.0.X`
4. `goreleaser release`

## Contributors

Contributions welcome! Make sure to `pre-commit install`

0 comments on commit e36f64c

Please sign in to comment.