feat: use goreleaser
This commit is contained in:
parent
4e23b5f299
commit
23da9d9aea
21
.gitea/workflows/golang-tests.yaml
Normal file
21
.gitea/workflows/golang-tests.yaml
Normal file
@ -0,0 +1,21 @@
|
||||
name: Golang Tests
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
types: [ "opened", "reopened", "synchronize" ]
|
||||
push:
|
||||
branches: [ '**' ]
|
||||
tags-ignore: [ '**' ]
|
||||
|
||||
jobs:
|
||||
unittest:
|
||||
runs-on:
|
||||
- ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4.2.2
|
||||
- uses: actions/setup-go@v5.5.0
|
||||
with:
|
||||
go-version: stable
|
||||
- env:
|
||||
GOPROXY: ${{ vars.GOPROXY }}
|
||||
run: make test/unit
|
18
.gitea/workflows/markdown-linters.yaml
Normal file
18
.gitea/workflows/markdown-linters.yaml
Normal file
@ -0,0 +1,18 @@
|
||||
name: Lint Markdown files
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
types: [ "opened", "reopened", "synchronize" ]
|
||||
push:
|
||||
branches: [ '**' ]
|
||||
tags-ignore: [ '**' ]
|
||||
|
||||
jobs:
|
||||
markdown-lint:
|
||||
runs-on:
|
||||
- ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4.2.2
|
||||
- uses: DavidAnson/markdownlint-cli2-action@v20.0.0
|
||||
with:
|
||||
globs: '**/*.md'
|
52
.gitea/workflows/release.yaml
Normal file
52
.gitea/workflows/release.yaml
Normal file
@ -0,0 +1,52 @@
|
||||
name: Release
|
||||
|
||||
on:
|
||||
push:
|
||||
tags: [ '**' ]
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
jobs:
|
||||
release:
|
||||
runs-on:
|
||||
- ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4.2.2
|
||||
- uses: docker/setup-qemu-action@v3.6.0
|
||||
- uses: actions/setup-go@v5.5.0
|
||||
with:
|
||||
go-version: stable
|
||||
- uses: docker/login-action@v3.4.0
|
||||
with:
|
||||
registry: git.cryptic.systems
|
||||
username: ${{ github.repository_owner }}
|
||||
password: ${{ secrets.GIT_CRYPTIC_SYSTEMS_PACKAGE_REGISTRY_TOKEN }}
|
||||
- env:
|
||||
GITEA_TOKEN: ${{ secrets.GIT_CRYPTIC_SYSTEMS_PACKAGE_REGISTRY_TOKEN }}
|
||||
GONOSUMDB: ${{ vars.GONOSUMDB }}
|
||||
GOPROXY: ${{ vars.GOPROXY }}
|
||||
uses: goreleaser/goreleaser-action@v6.3.0
|
||||
with:
|
||||
version: "~> v2"
|
||||
args: release --clean
|
||||
|
||||
sync-to-hub-docker-io:
|
||||
needs:
|
||||
- release
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Copy images to docker.io
|
||||
run: |
|
||||
TAG=$(echo ${{ github.ref_name }} | sed 's/v//gm')
|
||||
|
||||
apt-get update --yes
|
||||
apt-get install --yes skopeo
|
||||
skopeo copy \
|
||||
--all \
|
||||
--dest-password ${{ secrets.DOCKER_IO_PASSWORD }} \
|
||||
--dest-username ${{ secrets.DOCKER_IO_USERNAME }} \
|
||||
--src-password ${{ secrets.GIT_CRYPTIC_SYSTEMS_PACKAGE_REGISTRY_TOKEN }} \
|
||||
--src-username volker.raschek \
|
||||
docker://git.cryptic.systems/volker.raschek/dcmerge:${TAG} \
|
||||
docker://docker.io/volkerraschek/dcmerge:${TAG}
|
19
.gitea/workflows/update-docker-hub-description.yaml
Normal file
19
.gitea/workflows/update-docker-hub-description.yaml
Normal file
@ -0,0 +1,19 @@
|
||||
name: Update Docker Hub Description
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ 'master' ]
|
||||
paths: [ 'README.md' ]
|
||||
|
||||
jobs:
|
||||
update-description-on-hub-docker-io:
|
||||
runs-on:
|
||||
- ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4.2.2
|
||||
- uses: peter-evans/dockerhub-description@v4.0.2
|
||||
with:
|
||||
username: ${{ secrets.DOCKER_IO_USERNAME }}
|
||||
password: ${{ secrets.DOCKER_IO_PASSWORD }}
|
||||
repository: volkerraschek/docker-hub-description-updater
|
||||
readme-filepath: README.md
|
251
Makefile
251
Makefile
@ -1,195 +1,114 @@
|
||||
# VERSION
|
||||
# If no version is specified as a parameter of make, the last git hash
|
||||
# value is taken.
|
||||
# VERSION?=$(shell git describe --abbrev=0)+hash.$(shell git rev-parse --short HEAD)
|
||||
VERSION?=0.0.0+hash.$(shell git rev-parse --short HEAD)
|
||||
EXECUTABLE=docker-hub-description-updater
|
||||
VERSION?=$(shell git describe --abbrev=0)+hash.$(shell git rev-parse --short HEAD)
|
||||
|
||||
# EXECUTABLE
|
||||
# Executable binary which should be compiled for different architecures
|
||||
EXECUTABLE:=dhdu
|
||||
|
||||
# LINUX_EXECUTABLES AND TARGETS
|
||||
LINUX_EXECUTABLES:=\
|
||||
linux/amd64/${EXECUTABLE} \
|
||||
linux/arm/5/${EXECUTABLE} \
|
||||
linux/arm/7/${EXECUTABLE}
|
||||
|
||||
LINUX_EXECUTABLE_TARGETS:=${LINUX_EXECUTABLES:%=bin/%}
|
||||
|
||||
# UNIX_EXECUTABLES AND TARGETS
|
||||
# Define all executables for different architectures and operation systems
|
||||
UNIX_EXECUTABLES:=\
|
||||
${LINUX_EXECUTABLES}
|
||||
|
||||
UNIX_EXECUTABLE_TARGETS:=\
|
||||
${LINUX_EXECUTABLE_TARGETS}
|
||||
|
||||
# EXECUTABLE_TARGETS
|
||||
# Include all UNIX and Windows targets.
|
||||
EXECUTABLES:=\
|
||||
${UNIX_EXECUTABLES}
|
||||
|
||||
EXECUTABLE_TARGETS:=\
|
||||
${UNIX_EXECUTABLE_TARGETS}
|
||||
# Destination directory and prefix to place the compiled binaries, documentaions
|
||||
# and other files.
|
||||
DESTDIR?=
|
||||
PREFIX?=/usr/local
|
||||
|
||||
# CONTAINER_RUNTIME
|
||||
# The CONTAINER_RUNTIME variable will be used to specified the path to a
|
||||
# container runtime. This is needed to start and run a container images.
|
||||
CONTAINER_RUNTIME?=$(shell which docker)
|
||||
# container runtime. This is needed to start and run a container image.
|
||||
CONTAINER_RUNTIME?=$(shell which podman)
|
||||
|
||||
# BUILD_IMAGE
|
||||
# Definition of the container build image, in which the Binary are compiled from
|
||||
# source code
|
||||
BUILD_IMAGE_REGISTRY:=docker.io
|
||||
BUILD_IMAGE_NAMESPACE:=volkerraschek
|
||||
BUILD_IMAGE_NAME:=build-image
|
||||
BUILD_IMAGE_VERSION:=latest
|
||||
BUILD_IMAGE_FULL=${BUILD_IMAGE_REGISTRY}/${BUILD_IMAGE_NAMESPACE}/${BUILD_IMAGE_NAME}:${BUILD_IMAGE_VERSION:v%=%}
|
||||
BUILD_IMAGE_SHORT=${BUILD_IMAGE_NAMESPACE}/${BUILD_IMAGE_NAME}:${BUILD_IMAGE_VERSION:v%=%}
|
||||
# DOCKERHUB_DESCRIPTION_UPDATER_IMAGE_REGISTRY_NAME
|
||||
# Defines the name of the new container to be built using several variables.
|
||||
DOCKERHUB_DESCRIPTION_UPDATER_IMAGE_REGISTRY_NAME:=git.cryptic.systems
|
||||
DOCKERHUB_DESCRIPTION_UPDATER_IMAGE_REGISTRY_USER:=volker.raschek
|
||||
|
||||
# BASE_IMAGE
|
||||
# Definition of the base container image
|
||||
BASE_IMAGE_REGISTRY:=docker.io
|
||||
BASE_IMAGE_NAMESPACE:=library
|
||||
BASE_IMAGE_NAME:=alpine
|
||||
BASE_IMAGE_VERSION:=3.11.2
|
||||
BASE_IMAGE_FULL=${BASE_IMAGE_REGISTRY}/${BASE_IMAGE_NAMESPACE}/${BASE_IMAGE_NAME}:${BASE_IMAGE_VERSION:v%=%}
|
||||
BASE_IMAGE_SHORT=${BASE_IMAGE_NAMESPACE}/${BASE_IMAGE_NAME}:${BASE_IMAGE_VERSION:v%=%}
|
||||
DOCKERHUB_DESCRIPTION_UPDATER_IMAGE_NAMESPACE?=${DOCKERHUB_DESCRIPTION_UPDATER_IMAGE_REGISTRY_USER}
|
||||
DOCKERHUB_DESCRIPTION_UPDATER_IMAGE_NAME:=${EXECUTABLE}
|
||||
DOCKERHUB_DESCRIPTION_UPDATER_IMAGE_VERSION?=latest
|
||||
DOCKERHUB_DESCRIPTION_UPDATER_IMAGE_FULLY_QUALIFIED=${DOCKERHUB_DESCRIPTION_UPDATER_IMAGE_REGISTRY_NAME}/${DOCKERHUB_DESCRIPTION_UPDATER_IMAGE_NAMESPACE}/${DOCKERHUB_DESCRIPTION_UPDATER_IMAGE_NAME}:${DOCKERHUB_DESCRIPTION_UPDATER_IMAGE_VERSION}
|
||||
|
||||
# CONTAINER_IMAGE
|
||||
# Definition of the container image
|
||||
CONTAINER_IMAGE_REGISTRY:=docker.io
|
||||
CONTAINER_IMAGE_NAMESPACE:=volkerraschek
|
||||
CONTAINER_IMAGE_NAME:=${EXECUTABLE}
|
||||
CONTAINER_IMAGE_VERSION:=latest
|
||||
CONTAINER_IMAGE_FULL=${CONTAINER_IMAGE_REGISTRY}/${CONTAINER_IMAGE_NAMESPACE}/${CONTAINER_IMAGE_NAME}:${CONTAINER_IMAGE_VERSION:v%=%}
|
||||
CONTAINER_IMAGE_SHORT=${CONTAINER_IMAGE_NAMESPACE}/${CONTAINER_IMAGE_NAME}:${CONTAINER_IMAGE_VERSION:v%=%}
|
||||
|
||||
README_FILE:=README.md
|
||||
|
||||
# BINARIES
|
||||
# BIN
|
||||
# ==============================================================================
|
||||
PHONY:=all
|
||||
|
||||
${EXECUTABLE}: bin/tmp/${EXECUTABLE}
|
||||
|
||||
all: ${EXECUTABLE_TARGETS}
|
||||
|
||||
bin/linux/amd64/${EXECUTABLE}: bindata
|
||||
docker-hub-description-updater:
|
||||
CGO_ENABLED=0 \
|
||||
GOOS=linux \
|
||||
GOARCH=amd64 \
|
||||
GOPROXY=${GOPROXY} \
|
||||
GOPRIVATE=${GOPRIVATE} \
|
||||
go build -ldflags "-X main.version=${VERSION}" -o ${@}
|
||||
|
||||
bin/linux/arm/5/${EXECUTABLE}: bindata
|
||||
CGO_ENABLED=0 \
|
||||
GOOS=linux \
|
||||
GOARCH=arm \
|
||||
GOARM=5 \
|
||||
GOPROXY=${GOPROXY} \
|
||||
GOPRIVATE=${GOPRIVATE} \
|
||||
go build -ldflags "-X main.version=${VERSION}" -o ${@}
|
||||
|
||||
bin/linux/arm/7/${EXECUTABLE}: bindata
|
||||
CGO_ENABLED=0 \
|
||||
GOOS=linux \
|
||||
GOARCH=arm \
|
||||
GOARM=5 \
|
||||
GOPROXY=${GOPROXY} \
|
||||
GOPRIVATE=${GOPRIVATE} \
|
||||
go build -ldflags "-X main.version=${VERSION}" -o ${@}
|
||||
|
||||
bin/tmp/${EXECUTABLE}: bindata
|
||||
GOPROXY=${GOPROXY} \
|
||||
GOPRIVATE=${GOPRIVATE} \
|
||||
go build -ldflags "-X main.version=${VERSION}" -o ${@}
|
||||
|
||||
# BINDATA
|
||||
# ==============================================================================
|
||||
BINDATA_TARGETS := \
|
||||
pkg/hub/bindata.go
|
||||
|
||||
PHONY+=bindata
|
||||
bindata: ${BINDATA_TARGETS}
|
||||
|
||||
pkg/hub/bindata.go:
|
||||
go-bindata -pkg hub -o ${@} README.md
|
||||
|
||||
# TEST
|
||||
# ==============================================================================
|
||||
PHONY+=test
|
||||
test: clean bin/tmp/${EXECUTABLE}
|
||||
REGISTRY_USER=${REGISTRY_USER} \
|
||||
REGISTRY_PASSWORD=${REGISTRY_PASSWORD} \
|
||||
REGISTRY_NAMESPACE=${REGISTRY_NAMESPACE} \
|
||||
CONTAINER_IMAGE_NAME=${CONTAINER_IMAGE_NAME} \
|
||||
README_FILE=${README_FILE} \
|
||||
go test -v ./pkg/...
|
||||
GOPROXY=$(shell go env GOPROXY) \
|
||||
go build -ldflags "-X 'main.version=${VERSION}'" -o ${@} main.go
|
||||
|
||||
# CLEAN
|
||||
# ==============================================================================
|
||||
PHONY+=clean
|
||||
clean:
|
||||
rm --force ${EXECUTABLE} || true
|
||||
rm --force --recursive bin || true
|
||||
rm --force --recursive ${BINDATA_TARGETS} || true
|
||||
rm --force --recursive docker-hub-description-updater
|
||||
|
||||
# CONTAINER IMAGE STEPS
|
||||
# TESTS
|
||||
# ==============================================================================
|
||||
PHONY+=container-image/build/amd64
|
||||
container-image/build/amd64:
|
||||
PHONY+=test/unit
|
||||
test/unit:
|
||||
CGO_ENABLED=0 \
|
||||
GOPROXY=$(shell go env GOPROXY) \
|
||||
go test -v -p 1 -coverprofile=coverage.txt -covermode=count -timeout 1200s ./pkg/...
|
||||
|
||||
PHONY+=test/integration
|
||||
test/integration:
|
||||
CGO_ENABLED=0 \
|
||||
GOPROXY=$(shell go env GOPROXY) \
|
||||
go test -v -p 1 -count=1 -timeout 1200s ./it/...
|
||||
|
||||
PHONY+=test/coverage
|
||||
test/coverage: test/unit
|
||||
CGO_ENABLED=0 \
|
||||
GOPROXY=$(shell go env GOPROXY) \
|
||||
go tool cover -html=coverage.txt
|
||||
|
||||
# GOLANGCI-LINT
|
||||
# ==============================================================================
|
||||
PHONY+=golangci-lint
|
||||
golangci-lint:
|
||||
golangci-lint run --concurrency=$(shell nproc)
|
||||
|
||||
# INSTALL
|
||||
# ==============================================================================
|
||||
PHONY+=uninstall
|
||||
install: docker-hub-description-updater
|
||||
install --directory ${DESTDIR}/etc/bash_completion.d
|
||||
./docker-hub-description-updater completion bash > ${DESTDIR}/etc/bash_completion.d/${EXECUTABLE}
|
||||
|
||||
install --directory ${DESTDIR}${PREFIX}/bin
|
||||
install --mode 0755 ${EXECUTABLE} ${DESTDIR}${PREFIX}/bin/${EXECUTABLE}
|
||||
|
||||
install --directory ${DESTDIR}${PREFIX}/share/licenses/${EXECUTABLE}
|
||||
install --mode 0644 LICENSE ${DESTDIR}${PREFIX}/share/licenses/${EXECUTABLE}/LICENSE
|
||||
|
||||
# UNINSTALL
|
||||
# ==============================================================================
|
||||
PHONY+=uninstall
|
||||
uninstall:
|
||||
-rm --force --recursive \
|
||||
${DESTDIR}/etc/bash_completion.d/${EXECUTABLE} \
|
||||
${DESTDIR}${PREFIX}/bin/${EXECUTABLE} \
|
||||
${DESTDIR}${PREFIX}/share/licenses/${EXECUTABLE}
|
||||
|
||||
# BUILD CONTAINER IMAGE
|
||||
# ==============================================================================
|
||||
PHONY+=container-image/build
|
||||
container-image/build:
|
||||
${CONTAINER_RUNTIME} build \
|
||||
--build-arg BASE_IMAGE=${BASE_IMAGE_FULL} \
|
||||
--build-arg BUILD_IMAGE=${BUILD_IMAGE_FULL} \
|
||||
--build-arg EXECUTABLE=${EXECUTABLE} \
|
||||
--build-arg EXECUTABLE_TARGET=bin/linux/amd64/${EXECUTABLE} \
|
||||
--build-arg GOPROXY \
|
||||
--build-arg GOPRIVATE \
|
||||
--build-arg VERSION=${VERSION} \
|
||||
--file Dockerfile \
|
||||
--no-cache \
|
||||
--tag ${CONTAINER_IMAGE_FULL} \
|
||||
--tag ${CONTAINER_IMAGE_SHORT} \
|
||||
--pull \
|
||||
--tag ${DOCKERHUB_DESCRIPTION_UPDATER_IMAGE_FULLY_QUALIFIED} \
|
||||
.
|
||||
|
||||
PHONY+=container-image/push/amd64
|
||||
container-image/push/amd64: container-image/build/amd64
|
||||
${CONTAINER_RUNTIME} login ${CONTAINER_IMAGE_REGISTRY} \
|
||||
--username ${CONTAINER_IMAGE_REGISTRY_USER} \
|
||||
--password ${CONTAINER_IMAGE_REGISTRY_PASSWORD}
|
||||
${CONTAINER_RUNTIME} push ${CONTAINER_IMAGE_FULL}
|
||||
|
||||
# CONTAINER STEPS - BINARY
|
||||
# DELETE CONTAINER IMAGE
|
||||
# ==============================================================================
|
||||
PHONY+=container-run/all
|
||||
container-run/all:
|
||||
$(MAKE) container-run COMMAND=${@:container-run/%=%}
|
||||
PHONY:=container-image/delete
|
||||
container-image/delete:
|
||||
- ${CONTAINER_RUNTIME} image rm ${DOCKERHUB_DESCRIPTION_UPDATER_IMAGE_FULLY_QUALIFIED}
|
||||
|
||||
PHONY+=${UNIX_EXECUTABLE_TARGETS:%=container-run/%}
|
||||
${UNIX_EXECUTABLE_TARGETS:%=container-run/%}:
|
||||
$(MAKE) container-run COMMAND=${@:container-run/%=%}
|
||||
|
||||
# CONTAINER STEPS - CLEAN
|
||||
# PUSH CONTAINER IMAGE
|
||||
# ==============================================================================
|
||||
PHONY+=container-run/clean
|
||||
container-run/clean:
|
||||
$(MAKE) container-run COMMAND=${@:container-run/%=%}
|
||||
|
||||
# GENERAL CONTAINER COMMAND
|
||||
# ==============================================================================
|
||||
PHONY+=container-run
|
||||
container-run:
|
||||
${CONTAINER_RUNTIME} run \
|
||||
--rm \
|
||||
--volume ${PWD}:/workspace \
|
||||
${BUILD_IMAGE_FULL} \
|
||||
make ${COMMAND} \
|
||||
VERSION=${VERSION} \
|
||||
GOPROXY=${GOPROXY} \
|
||||
GOPRIVATE=${GOPRIVATE} \
|
||||
PHONY+=container-image/push
|
||||
container-image/push:
|
||||
echo ${DOCKERHUB_DESCRIPTION_UPDATER_IMAGE_REGISTRY_PASSWORD} | ${CONTAINER_RUNTIME} login ${DOCKERHUB_DESCRIPTION_UPDATER_IMAGE_REGISTRY_NAME} --username ${DOCKERHUB_DESCRIPTION_UPDATER_IMAGE_REGISTRY_USER} --password-stdin
|
||||
${CONTAINER_RUNTIME} push ${DOCKERHUB_DESCRIPTION_UPDATER_IMAGE_FULLY_QUALIFIED}
|
||||
|
||||
# PHONY
|
||||
# ==============================================================================
|
||||
# Declare the contents of the PHONY variable as phony. We keep that information
|
||||
# in a variable so we can use it in if_changed.
|
||||
.PHONY: ${PHONY}
|
16
cmd/root.go
16
cmd/root.go
@ -19,7 +19,7 @@ var (
|
||||
)
|
||||
|
||||
// Execute a
|
||||
func Execute(version string) {
|
||||
func Execute(version string) error {
|
||||
rootCmd := &cobra.Command{
|
||||
Use: "dhdu",
|
||||
Short: "docker hub description updater (dhdu)",
|
||||
@ -31,7 +31,7 @@ func Execute(version string) {
|
||||
rootCmd.Flags().StringVarP(&dockerHubPassword, "password", "p", "", "Docker Hub Password")
|
||||
rootCmd.Flags().StringVarP(&dockerHubRepository, "repository", "r", "", "Docker Hub Repository")
|
||||
rootCmd.Flags().StringVarP(&dockerHubUser, "username", "u", "", "Docker Hub Username")
|
||||
rootCmd.Execute()
|
||||
return rootCmd.Execute()
|
||||
}
|
||||
|
||||
func runE(cmd *cobra.Command, args []string) error {
|
||||
@ -39,29 +39,29 @@ func runE(cmd *cobra.Command, args []string) error {
|
||||
file := args[0]
|
||||
|
||||
if len(dockerHubUser) <= 0 {
|
||||
return fmt.Errorf("No user defined over flags")
|
||||
return fmt.Errorf("no user defined over flags")
|
||||
}
|
||||
|
||||
if len(dockerHubPassword) <= 0 {
|
||||
return fmt.Errorf("No password defined over flags")
|
||||
return fmt.Errorf("no password defined over flags")
|
||||
}
|
||||
|
||||
if len(dockerHubNamespace) <= 0 {
|
||||
log.Printf("No namespace defined over flags: Use docker username %v instead", dockerHubUser)
|
||||
log.Printf("no namespace defined over flags: Use docker username %v instead", dockerHubUser)
|
||||
dockerHubNamespace = dockerHubUser
|
||||
}
|
||||
|
||||
if len(dockerHubRepository) <= 0 {
|
||||
return fmt.Errorf("No repository defined over flags")
|
||||
return fmt.Errorf("nNo repository defined over flags")
|
||||
}
|
||||
|
||||
if _, err := os.Stat(file); os.IsNotExist(err) && len(file) <= 0 {
|
||||
return fmt.Errorf("Can not find file: %v", file)
|
||||
return fmt.Errorf("can not find file: %v", file)
|
||||
}
|
||||
|
||||
f, err := ioutil.ReadFile(file)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Can not read file %v: %v", file, err)
|
||||
return fmt.Errorf("can not read file %v: %v", file, err)
|
||||
}
|
||||
fullDescription := string(f)
|
||||
|
||||
|
16
go.mod
16
go.mod
@ -1,16 +1,10 @@
|
||||
module github.com/volker-raschek/docker-hub-description-updater
|
||||
|
||||
go 1.18
|
||||
go 1.24
|
||||
|
||||
require github.com/spf13/cobra v1.9.1
|
||||
|
||||
require (
|
||||
github.com/spf13/cobra v0.0.3
|
||||
github.com/stretchr/testify v1.4.0
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/inconshreveable/mousetrap v1.0.0 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
github.com/spf13/pflag v1.0.5 // indirect
|
||||
gopkg.in/yaml.v2 v2.2.2 // indirect
|
||||
github.com/inconshreveable/mousetrap v1.1.0 // indirect
|
||||
github.com/spf13/pflag v1.0.6 // indirect
|
||||
)
|
||||
|
26
go.sum
26
go.sum
@ -1,18 +1,10 @@
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
|
||||
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/spf13/cobra v0.0.3 h1:ZlrZ4XsMRm04Fr5pSFxBgfND2EBVa1nLpiy1stUsX/8=
|
||||
github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
|
||||
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
|
||||
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
|
||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
|
||||
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
|
||||
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
|
||||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||
github.com/spf13/cobra v1.9.1 h1:CXSaggrXdbHK9CF+8ywj8Amf7PBRmPCOJugH954Nnlo=
|
||||
github.com/spf13/cobra v1.9.1/go.mod h1:nDyEzZ8ogv936Cinf6g1RU9MRY64Ir93oCnqb9wxYW0=
|
||||
github.com/spf13/pflag v1.0.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o=
|
||||
github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
2
main.go
2
main.go
@ -9,5 +9,5 @@ var (
|
||||
)
|
||||
|
||||
func main() {
|
||||
cmd.Execute(version)
|
||||
_ = cmd.Execute(version)
|
||||
}
|
||||
|
@ -3,13 +3,11 @@ package hub
|
||||
import "errors"
|
||||
|
||||
var (
|
||||
errorFailedToCreateRequest = errors.New("Failed to create http request")
|
||||
errorFailedToParseJSON = errors.New("Failed to parse json")
|
||||
errorFailedToParseURL = errors.New("Failed to parse url")
|
||||
errorFailedToSendRequest = errors.New("Failed to send http request")
|
||||
errorNoUserDefined = errors.New("No User defined")
|
||||
errorNoPasswordDefined = errors.New("No Password defined")
|
||||
errorNoNamespaceDefined = errors.New("No Namespace defined")
|
||||
errorNoRepositoryDefined = errors.New("No Repository defined")
|
||||
errorUnexpectedHTTPStatuscode = errors.New("Unexpected HTTP-Statuscode")
|
||||
errorFailedToCreateRequest = errors.New("failed to create http request")
|
||||
errorFailedToParseJSON = errors.New("failed to parse json")
|
||||
errorFailedToParseURL = errors.New("failed to parse url")
|
||||
errorFailedToSendRequest = errors.New("failed to send http request")
|
||||
errorNoNamespaceDefined = errors.New("no Namespace defined")
|
||||
errorNoRepositoryDefined = errors.New("no Repository defined")
|
||||
errorUnexpectedHTTPStatuscode = errors.New("unexpected HTTP-Statuscode")
|
||||
)
|
||||
|
@ -56,7 +56,7 @@ func (h *Hub) GetRepository(namespace string, name string) (*types.Repository, e
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("%v: %v", errorFailedToSendRequest, err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
defer func() { _ = resp.Body.Close() }()
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return nil, fmt.Errorf("%v: expect %v, received %v", errorUnexpectedHTTPStatuscode, http.StatusOK, resp.StatusCode)
|
||||
@ -89,7 +89,7 @@ func (h *Hub) getToken() (*types.Token, error) {
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("%v: %v", errorFailedToCreateRequest, err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
defer func() { _ = resp.Body.Close() }()
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return nil, fmt.Errorf("%v: expect %v, received %v", errorUnexpectedHTTPStatuscode, http.StatusOK, resp.StatusCode)
|
||||
@ -144,7 +144,7 @@ func (h *Hub) PatchRepository(repository *types.Repository) (*types.Repository,
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("%v: %v", errorFailedToCreateRequest, err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
defer func() { _ = resp.Body.Close() }()
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return nil, fmt.Errorf("%v: expect %v, received %v", errorUnexpectedHTTPStatuscode, http.StatusOK, resp.StatusCode)
|
||||
|
@ -1,54 +0,0 @@
|
||||
package hub
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/volker-raschek/docker-hub-description-updater/pkg/types"
|
||||
)
|
||||
|
||||
func TestPatchRepository(t *testing.T) {
|
||||
|
||||
dockerHubUser := os.Getenv("REGISTRY_USER")
|
||||
if len(dockerHubUser) <= 0 {
|
||||
t.Fatalf("Environment variable REGISTRY_USER is empty")
|
||||
}
|
||||
|
||||
dockerHubPassword := os.Getenv("REGISTRY_PASSWORD")
|
||||
if len(dockerHubPassword) <= 0 {
|
||||
t.Fatalf("Environment variable REGISTRY_PASSWORD is empty")
|
||||
}
|
||||
|
||||
dockerHubNamespace := os.Getenv("REGISTRY_NAMESPACE")
|
||||
if len(dockerHubNamespace) <= 0 {
|
||||
t.Fatalf("Environment variable REGISTRY_NAMESPACE is empty")
|
||||
}
|
||||
|
||||
dockerHubRepository := os.Getenv("CONTAINER_IMAGE_NAME")
|
||||
if len(dockerHubRepository) <= 0 {
|
||||
t.Fatalf("Environment variable CONTAINER_IMAGE_NAME is empty")
|
||||
}
|
||||
|
||||
loginCredentials := &types.LoginCredentials{
|
||||
User: dockerHubUser,
|
||||
Password: dockerHubPassword,
|
||||
}
|
||||
|
||||
h := New(loginCredentials)
|
||||
|
||||
require := require.New(t)
|
||||
|
||||
readme, err := Asset("README.md")
|
||||
require.NoError(err)
|
||||
|
||||
currentRepository, err := h.GetRepository(dockerHubNamespace, dockerHubRepository)
|
||||
require.NoError(err)
|
||||
|
||||
expectedRepository := *currentRepository
|
||||
expectedRepository.FullDescription = string(readme)
|
||||
|
||||
actualRepository, err := h.PatchRepository(&expectedRepository)
|
||||
require.NoError(err)
|
||||
require.EqualValues(&expectedRepository.FullDescription, actualRepository.FullDescription, "Full description not equal")
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user