commit 28985797d1e9effc6456fa9cf4c106d65e70fe68 Author: Jan Gräfen Date: Fri Mar 5 16:35:21 2021 +0100 Prepare initial project layout diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..aabcf76 --- /dev/null +++ b/.editorconfig @@ -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 \ No newline at end of file diff --git a/.github/workflow/build.yml b/.github/workflow/build.yml new file mode 100644 index 0000000..ca5bce0 --- /dev/null +++ b/.github/workflow/build.yml @@ -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/ diff --git a/.github/workflow/release.yml b/.github/workflow/release.yml new file mode 100644 index 0000000..3c853fe --- /dev/null +++ b/.github/workflow/release.yml @@ -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 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..29b636a --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.idea +*.iml \ No newline at end of file diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..aa1f4b4 --- /dev/null +++ b/.golangci.yml @@ -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 diff --git a/.golangreleaser.yml b/.golangreleaser.yml new file mode 100644 index 0000000..d2cfc7b --- /dev/null +++ b/.golangreleaser.yml @@ -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:' diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..0fc6e80 --- /dev/null +++ b/Dockerfile @@ -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"] diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..0032b04 --- /dev/null +++ b/LICENSE @@ -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. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..8880b7d --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# hcloud-pricing-exporter diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..d093a96 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module "github.com/jangraefen/hcloud-pricing-exporter" + +go 1.16 \ No newline at end of file