Skip to content

Commit

Permalink
Update dependencies (#34)
Browse files Browse the repository at this point in the history
* Update dependencies

* Add lint workflow and fix issues

* Replace Travis with GH actions

* Update K8s deps
  • Loading branch information
coufalja authored Apr 24, 2023
1 parent 58d97ae commit 33fc282
Show file tree
Hide file tree
Showing 20 changed files with 818 additions and 438 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Lint
on:
pull_request:
jobs:
golangci:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Install Go
uses: actions/setup-go@v4
with:
go-version-file: go.mod
- name: Lint
uses: wandera/golangci-lint-action@v3
with:
version: v1.51.2
38 changes: 38 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Release

on:
push:
tags:
- "v*.*.*"

env:
TAG: ${{ github.ref_name }}

jobs:
release-binary:
runs-on: ubuntu-latest
strategy:
matrix:
goos: [linux, darwin]
goarch: [arm64, amd64]
steps:
- name: Checkout the latest code
uses: actions/checkout@v3
- name: Install Go
uses: actions/setup-go@v4
with:
go-version-file: go.mod
- name: Build ${{ matrix.goos }}/${{ matrix.goarch }}
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
shell: bash
run: |
GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} go build -o git2kube -ldflags '-w -s -X 'github.com/wandera/git2kube/cmd.Version=${{ env.TAG }} \
&& mkdir dist \
&& mv git2kube dist/git2kube \
&& tar -czvf git2kube-${{ matrix.goos }}-${{ matrix.goarch }}.tar.gz -C dist/ .
- name: Release
uses: softprops/action-gh-release@v1
with:
files: git2kube-${{ matrix.goos }}-${{ matrix.goarch }}.tar.gz
51 changes: 51 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Test

on:
push:
branches:
- master
pull_request:
issue_comment:
types:
- created

jobs:
unit:
if: (github.event.issue.pull_request != '' && contains(github.event.comment.body, '/test')) || github.event_name == 'pull_request' || github.event_name == 'push'
strategy:
matrix:
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Install Go
uses: actions/setup-go@v4
with:
go-version-file: go.mod
- name: Test
run: go test -v ./...
build:
if: (github.event.issue.pull_request != '' && contains(github.event.comment.body, '/test')) || github.event_name == 'pull_request' || github.event_name == 'push'
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Docker build
uses: docker/build-push-action@v3
with:
context: .
build-args: |
VERSION=${{ github.ref_name }}
vulncheck:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Scan for Vulnerabilities in Code
uses: wandera/govulncheck-action@v0.0.10
with:
go-version: 1.20.0
package: ./...
39 changes: 39 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
run:
timeout: 5m
linters:
disable-all: true
enable:
- gci
- godot
- gofumpt
- gosimple
- govet
- gosec
- ineffassign
- staticcheck
- typecheck
- unparam
- unused
- whitespace

linters-settings:
gosec:
global:
audit: true
excludes:
- G104
- G304
- G401
- G501

issues:
exclude-rules:
# Exclude some linters from running on tests files.
- path: _test\.go
linters:
- ineffassign
- gosec

- linters:
- staticcheck
text: "SA4006:" #SA4006: this value of `not_used` is never used (staticcheck)
72 changes: 0 additions & 72 deletions .travis.yml

This file was deleted.

12 changes: 4 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
# Builder image
FROM golang:1.14.3 AS builder
FROM golang:1.20.1-alpine3.17 AS builder

WORKDIR /build
COPY go.mod go.sum ./
RUN go mod download

# Docker Cloud args, from hooks/build.
ARG CACHE_TAG
ENV CACHE_TAG ${CACHE_TAG}
ARG VERSION

COPY . .
RUN CGO_ENABLED=0 GOOS=linux go build -v -ldflags '-w -s -X 'github.com/wandera/git2kube/cmd.Version=${CACHE_TAG}
RUN --mount=type=cache,target=/go/pkg/mod --mount=type=cache,target=/root/.cache/go-build GOMODCACHE=/go/pkg/mod GOCACHE=/root/.cache/go-build go build -v -ldflags '-w -s -X 'github.com/wandera/git2kube/cmd.Version=${VERSION}

# Runtime image
FROM alpine:3.12
FROM alpine:3.17.3
RUN apk --no-cache add ca-certificates

RUN apk --no-cache --virtual .openssh add openssh \
Expand Down
4 changes: 2 additions & 2 deletions cmd/gendoc.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ var genDocCmd = &cobra.Command{
Use: "gendoc",
Short: "Generates documentation for this tool in Markdown format",
RunE: func(cmd *cobra.Command, args []string) error {
return executeGenDoc(args)
return executeGenDoc()
},
}

func executeGenDoc(args []string) error {
func executeGenDoc() error {
err := doc.GenMarkdownTree(rootCmd, docDestination)
return err
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/load.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package cmd

import (
"os"

"github.com/spf13/cobra"
"github.com/wandera/git2kube/pkg/cmd"
"github.com/wandera/git2kube/pkg/fetch"
"github.com/wandera/git2kube/pkg/upload"
"os"
)

var lp = struct {
Expand Down
3 changes: 2 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"fmt"

log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -33,7 +34,7 @@ func init() {
rootCmd.AddCommand(versionCmd)
}

//Execute run root command (main entrypoint)
// Execute run root command (main entrypoint).
func Execute() error {
return rootCmd.Execute()
}
3 changes: 2 additions & 1 deletion cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package cmd

import (
"fmt"

"github.com/spf13/cobra"
)

// Version variable is set at build time
// Version variable is set at build time.
var Version = "unknown"

var versionCmd = &cobra.Command{
Expand Down
16 changes: 8 additions & 8 deletions cmd/watch.go
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
package cmd

import (
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/wandera/git2kube/pkg/cmd"
"github.com/wandera/git2kube/pkg/fetch"
"github.com/wandera/git2kube/pkg/upload"
"io/ioutil"
"os"
"os/signal"
"path"
"syscall"
"time"

log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/wandera/git2kube/pkg/cmd"
"github.com/wandera/git2kube/pkg/fetch"
"github.com/wandera/git2kube/pkg/upload"
)

type healthCheckStatus string

const (
ok healthCheckStatus = "OK"
nok = "NOK"
nok healthCheckStatus = "NOK"
)

var wp = struct {
Expand Down Expand Up @@ -167,7 +167,7 @@ func writeHealthCheck(status healthCheckStatus) {
log.Errorf("Unable to create healthcheck folder")
}

err = ioutil.WriteFile(wp.healthCheckFile, []byte(status), 0644)
err = os.WriteFile(wp.healthCheckFile, []byte(status), 0o600)
if err != nil {
log.Errorf("Unable to write healthcheck file")
}
Expand Down
Loading

0 comments on commit 33fc282

Please sign in to comment.