Skip to content

Commit

Permalink
Merge pull request #39 from wandera/setup-repo
Browse files Browse the repository at this point in the history
Bump dependencies, use GitHub Actions instead of Travis CI
  • Loading branch information
mrackoa authored Apr 27, 2023
2 parents 52fa798 + f82cba5 commit c14c1c2
Show file tree
Hide file tree
Showing 44 changed files with 452 additions and 304 deletions.
23 changes: 23 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
version: 2
updates:
- package-ecosystem: "docker"
directory: "/"
schedule:
interval: "weekly"
reviewers:
- "wandera/delta"

- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
reviewers:
- "wandera/delta"

- package-ecosystem: "gomod"
directory: "/"
schedule:
interval: "weekly"
reviewers:
- "wandera/delta"

18 changes: 18 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
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
args: --out-${NO_FUTURE}format colored-line-number
89 changes: 89 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
name: Release

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

env:
REGISTRY: ghcr.io
BINARY_NAME: ${{ github.event.repository.name }}
IMAGE_NAME: ${{ github.repository }}
TAG: ${{ github.ref_name }}

jobs:
release-binary:
runs-on: ubuntu-latest
strategy:
matrix:
goos: [linux, windows, darwin]
goarch: [386, arm64, amd64]
exclude:
- goarch: "386"
goos: darwin
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: |
if [ "$GOOS" = "windows" ]; then
GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} go build -o dist/${{ env.BINARY_NAME }}.exe -ldflags '-w -s -X 'github.com/wandera/${{ env.BINARY_NAME }}/cmd.Version=${{ env.TAG }}
else
CGO_ENABLED=0 GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} go build -o dist/${{ env.BINARY_NAME }} -ldflags '-w -s -X 'github.com/wandera/${{ env.BINARY_NAME }}/cmd.Version=${{ env.TAG }}
fi
tar -czvf ${{ env.BINARY_NAME }}-${{ matrix.goos }}-${{ matrix.goarch }}.tar.gz -C dist/ .
- name: Release
uses: wandera/action-gh-release@v1
with:
files: ${{ env.BINARY_NAME }}-${{ matrix.goos }}-${{ matrix.goarch }}.tar.gz

release-docker-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=semver,pattern={{raw}}
type=semver,pattern=v{{major}}.{{minor}}
type=semver,pattern=v{{major}}
type=sha
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Docker build & push
uses: docker/build-push-action@v4
with:
push: true
context: .
platforms: linux/amd64,linux/arm64
build-args: |
VERSION=${{ github.ref_name }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

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@v4
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)
75 changes: 0 additions & 75 deletions .travis.yml

This file was deleted.

14 changes: 5 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
# Builder image
FROM golang:1.14.3 AS builder
FROM golang:1.20.3-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/scccmd/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/scccmd/cmd.Version=${VERSION}

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

COPY --from=builder /build/scccmd /app/scccmd
WORKDIR /app

ENTRYPOINT ["./scccmd"]
ENTRYPOINT ["./scccmd"]
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# scccmd - Spring Cloud Config cli tool

[![Build Status](https://travis-ci.org/wandera/scccmd.svg?branch=master)](https://travis-ci.org/wandera/scccmd)
[![Docker Build Status](https://img.shields.io/docker/build/wanderadock/scccmd.svg)](https://hub.docker.com/r/wanderadock/scccmd/)
[![Test](https://github.com/wandera/scccmd/actions/workflows/test.yml/badge.svg)](https://github.com/wandera/scccmd/actions/workflows/test.yml)
[![Go Report Card](https://goreportcard.com/badge/github.com/wandera/scccmd)](https://goreportcard.com/report/github.com/wandera/scccmd)
[![GitHub release](https://img.shields.io/github/release/wandera/scccmd.svg)](https://github.com/wandera/scccmd/releases/latest)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/wandera/scccmd/blob/master/LICENSE)
Expand All @@ -15,7 +14,7 @@ Tool for obtaining configuration from config server
* Or if you dont want to setup your local go env just use the provided Dockerfile

### Docker repository
The tool is released as docker image as well, check the [repository](https://hub.docker.com/r/wanderadock/scccmd/).
The tool is released as docker image as well, check the [repository](https://github.com/wandera/git2kube/pkgs/container/scccmd).

### Kubernetes Initializer
The tool could be used as Webhook for Kubernetes deployments.
Expand All @@ -24,4 +23,4 @@ which in turn downloads configuration in deployment initialization phase.
Example k8s [manifest](docs/k8s/bundle.yaml).

### Tool documentation
[docs](docs/scccmd.md) - Generated documentation for the tool
[docs](docs/scccmd.md) - Generated documentation for the tool
9 changes: 5 additions & 4 deletions cmd/decrypt.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package cmd

import (
"fmt"
"io"
"os"

"github.com/spf13/cobra"
"github.com/wandera/scccmd/pkg/client"
"io/ioutil"
"os"
)

var dp = struct {
Expand All @@ -21,10 +22,10 @@ var decryptCmd = &cobra.Command{
},
}

// ExecuteDecrypt runs decrypt cmd
// ExecuteDecrypt runs decrypt cmd.
func ExecuteDecrypt() error {
if dp.value == "" {
bytes, err := ioutil.ReadAll(os.Stdin)
bytes, err := io.ReadAll(os.Stdin)

dp.value = string(bytes)
if err != nil {
Expand Down
Loading

0 comments on commit c14c1c2

Please sign in to comment.