Prepare initial project layout

This commit is contained in:
Jan Gräfen 2021-03-05 16:35:21 +01:00
commit 28985797d1
10 changed files with 262 additions and 0 deletions

13
.editorconfig Normal file
View file

@ -0,0 +1,13 @@
root = true
[*]
charset = utf-8
end_of_line = crlf
indent_size = 4
indent_style = tab
insert_final_newline = true
max_line_length = 120
tab_width = 4
[{*.yaml, *.yml}]
indent_size = 2

74
.github/workflow/build.yml vendored Normal file
View file

@ -0,0 +1,74 @@
name: Build
on:
push:
branches: [ master ]
paths-ignore:
- README.md
- LICENSE
- .gitignore
- .editorconfig
pull_request:
branches: [ master ]
jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Install Go
uses: actions/setup-go@v1
with:
go-version: ^1.15
- name: Checkout code
uses: actions/checkout@v1
- name: Install golangci-lint
run: |
go get github.com/golangci/golangci-lint/cmd/golangci-lint
- name: Run linters
run: |
export PATH=$PATH:$(go env GOPATH)/bin
golangci-lint run
test:
name: Test
strategy:
matrix:
go-version: [ 1.15.x ]
platform: [ ubuntu-latest ]
runs-on: ${{ matrix.platform }}
needs: [ lint ]
steps:
- name: Install Go
if: success()
uses: actions/setup-go@v1
with:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@v1
- name: Run tests
run: go test -v -race -covermode=atomic ./...
build:
runs-on: ubuntu-latest
needs: [ test ]
steps:
- name: Install Go
uses: actions/setup-go@v1
with:
go-version: ^1.15
- name: Checkout code
uses: actions/checkout@v1
- name: Get dependencies
run: |
export GO111MODULE=on
go get -v -t -d ./...
- name: Build
run: |
export GO111MODULE=on
GOOS=linux GOARCH=amd64 go build -o bin/hcloud-pricing-exporter-linux-amd64 main.go
GOOS=linux GOARCH=arm64 go build -o bin/hcloud-pricing-exporter-linux-arm64 main.go
GOOS=windows GOARCH=amd64 go build -o bin/hcloud-pricing-exporter-windows-amd64.exe main.go
- name: Upload Artifacts
uses: actions/upload-artifact@master
with:
name: binaries
path: bin/

64
.github/workflow/release.yml vendored Normal file
View file

@ -0,0 +1,64 @@
name: Release
on:
push:
tags:
- 'v*'
jobs:
binaryrelease:
name: Binary Release
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.15
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
dockerrelease:
name: Docker Release
runs-on: ubuntu-latest
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v2
- name: Docker meta
id: docker_meta
uses: crazy-max/ghaction-docker-meta@v1
with:
images: jangraefen/hcloud-pricing-exporter
tag-sha: true
tag-semver: |
{{version}}
{{major}}.{{minor}}
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1
- name: Login to GitHub docker registry
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Build docker image
uses: docker/build-push-action@v2
with:
context: .
platforms: |
linux/amd64
linux/arm64/v8
tags: ${{ steps.docker_meta.outputs.tags }}
labels: ${{ steps.docker_meta.outputs.labels }}
push: true

2
.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
.idea
*.iml

25
.golangci.yml Normal file
View file

@ -0,0 +1,25 @@
linters:
enable:
- gosimple
- govet
- ineffassign
- staticcheck
- bodyclose
- dupl
- exportloopref
- funlen
- gocognit
- goconst
- gocritic
- gocyclo
- godot
- gofmt
- golint
- goprintffuncname
- gosec
- interfacer
- maligned
- prealloc
- stylecheck
- unconvert
- whitespace

42
.golangreleaser.yml Normal file
View file

@ -0,0 +1,42 @@
before:
hooks:
- go mod download
builds:
- id: "hcloud-pricing-exporter-cli"
main: ./main.go
binary: hcloud-pricing-exporter
env:
- CGO_ENABLED=0
- GO111MODULE=on
goos:
- linux
- windows
goarch:
- 386
- amd64
- arm
- arm64
archives:
- name_template: "hcloud-pricing-exporter-{{ .Version }}-{{ .Os }}-{{ .Arch }}"
format_overrides:
- goos: windows
format: zip
source:
enabled: true
name_template: "hcloud-pricing-exporter-{{ .Version }}.src"
checksum:
name_template: "hcloud-pricing-exporter-{{ .Version }}.checksums.txt"
milestones:
- close: true
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'

17
Dockerfile Normal file
View file

@ -0,0 +1,17 @@
ARG ARCH=""
FROM golang:alpine
# Create application directory
RUN mkdir /app
ADD . /app/
WORKDIR /app
# Build the application
RUN CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH} go build -o run .
# Add the execution user
RUN adduser -S -D -H -h /app execuser
USER execuser
# Run the application
ENTRYPOINT ["./run"]

21
LICENSE Normal file
View file

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2021 Jan Graefen
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.

1
README.md Normal file
View file

@ -0,0 +1 @@
# hcloud-pricing-exporter

3
go.mod Normal file
View file

@ -0,0 +1,3 @@
module "github.com/jangraefen/hcloud-pricing-exporter"
go 1.16