From 4c7ce56f1b7c877c6414df8da2575a3db08a9875 Mon Sep 17 00:00:00 2001 From: Markus Pesch Date: Sat, 31 May 2025 21:18:20 +0200 Subject: [PATCH] feat: use goreleaser --- .dockerignore | 1 - .drone.yml | 670 ------------------ .gitea/workflows/golang-tests.yaml | 21 + .gitea/workflows/markdown-linters.yaml | 20 + .gitea/workflows/release.yaml | 52 ++ .../update-docker-hub-description.yaml | 19 + .gitignore | 28 +- .golangci.yml | 29 - .goreleaser.yaml | 175 +++++ .markdownlint.yaml | 18 +- Dockerfile | 26 +- Makefile | 115 ++- README.md | 33 +- go.mod | 2 +- manifest.tmpl | 20 - pkg/dbwait/dbwait.go | 9 +- 16 files changed, 400 insertions(+), 838 deletions(-) delete mode 100644 .dockerignore delete mode 100644 .drone.yml create mode 100644 .gitea/workflows/golang-tests.yaml create mode 100644 .gitea/workflows/markdown-linters.yaml create mode 100644 .gitea/workflows/release.yaml create mode 100644 .gitea/workflows/update-docker-hub-description.yaml delete mode 100644 .golangci.yml create mode 100644 .goreleaser.yaml delete mode 100644 manifest.tmpl diff --git a/.dockerignore b/.dockerignore deleted file mode 100644 index 6f63422..0000000 --- a/.dockerignore +++ /dev/null @@ -1 +0,0 @@ -db-wait \ No newline at end of file diff --git a/.drone.yml b/.drone.yml deleted file mode 100644 index 5f390ac..0000000 --- a/.drone.yml +++ /dev/null @@ -1,670 +0,0 @@ ---- -kind: pipeline -type: kubernetes -name: linter - -clone: - disable: true - -platform: - os: linux - -steps: -- name: clone - image: git.cryptic.systems/volker.raschek/git:1.4.0 - -- name: markdown lint - commands: - - markdownlint *.md - image: git.cryptic.systems/volker.raschek/markdownlint:0.44.0 - resources: - limits: - cpu: 150 - memory: 150M - -- name: email-notification - environment: - SMTP_FROM_ADDRESS: - from_secret: smtp_from_address - SMTP_FROM_NAME: - from_secret: smtp_from_name - SMTP_HOST: - from_secret: smtp_host - SMTP_USERNAME: - from_secret: smtp_username - SMTP_PASSWORD: - from_secret: smtp_password - image: git.cryptic.systems/volker.raschek/drone-email:0.1.5 - resources: - limits: - cpu: 150 - memory: 150M - when: - status: - - changed - - failure - -trigger: - event: - exclude: - - tag - ---- -kind: pipeline -type: docker -name: dry-run-amd64 - -clone: - disable: true - -depends_on: -- linter - -platform: - os: linux - arch: amd64 - -steps: -- name: clone - image: git.cryptic.systems/volker.raschek/git:1.4.0 - -- name: build - image: docker.io/plugins/docker:20.18.8 - settings: - auto_tag: false - dockerfile: Dockerfile - dry_run: true - force_tag: true - no_cache: true - purge: true - mirror: - from_secret: docker_io_mirror - registry: git.cryptic.systems - repo: git.cryptic.systems/volker.raschek/db-wait - tags: latest-amd64 - username: - from_secret: git_cryptic_systems_container_registry_user - password: - from_secret: git_cryptic_systems_container_registry_password - -- name: email-notification - environment: - SMTP_FROM_ADDRESS: - from_secret: smtp_from_address - SMTP_FROM_NAME: - from_secret: smtp_from_name - SMTP_HOST: - from_secret: smtp_host - SMTP_USERNAME: - from_secret: smtp_username - SMTP_PASSWORD: - from_secret: smtp_password - image: git.cryptic.systems/volker.raschek/drone-email:0.1.5 - when: - status: - - changed - - failure - -trigger: - branch: - exclude: - - master - event: - - pull_request - - push - repo: - - volker.raschek/db-wait - ---- -kind: pipeline -type: docker -name: dry-run-arm64-v8 - -clone: - disable: true - -depends_on: -- linter - -platform: - os: linux - arch: arm64 - -steps: -- name: clone - image: git.cryptic.systems/volker.raschek/git:1.4.0 - -- name: build - image: docker.io/plugins/docker:20.18.8 - settings: - auto_tag: false - dockerfile: Dockerfile - dry_run: true - force_tag: true - no_cache: true - purge: true - mirror: - from_secret: docker_io_mirror - registry: git.cryptic.systems - repo: git.cryptic.systems/volker.raschek/db-wait - tags: latest-arm64-v8 - username: - from_secret: git_cryptic_systems_container_registry_user - password: - from_secret: git_cryptic_systems_container_registry_password - -- name: email-notification - environment: - SMTP_FROM_ADDRESS: - from_secret: smtp_from_address - SMTP_FROM_NAME: - from_secret: smtp_from_name - SMTP_HOST: - from_secret: smtp_host - SMTP_USERNAME: - from_secret: smtp_username - SMTP_PASSWORD: - from_secret: smtp_password - image: git.cryptic.systems/volker.raschek/drone-email:0.1.5 - when: - status: - - changed - - failure - -trigger: - branch: - exclude: - - master - event: - - pull_request - - push - repo: - - volker.raschek/db-wait - ---- -kind: pipeline -type: docker -name: latest-amd64 - -clone: - disable: true - -depends_on: -- linter - -platform: - os: linux - arch: amd64 - -steps: -- name: clone - image: git.cryptic.systems/volker.raschek/git:1.4.0 - -- name: build - image: docker.io/plugins/docker:20.18.8 - settings: - auto_tag: false - dockerfile: Dockerfile - force_tag: true - no_cache: true - purge: true - mirror: - from_secret: docker_io_mirror - registry: git.cryptic.systems - repo: git.cryptic.systems/volker.raschek/db-wait - tags: latest-amd64 - username: - from_secret: git_cryptic_systems_container_registry_user - password: - from_secret: git_cryptic_systems_container_registry_password - -- name: email-notification - environment: - SMTP_FROM_ADDRESS: - from_secret: smtp_from_address - SMTP_FROM_NAME: - from_secret: smtp_from_name - SMTP_HOST: - from_secret: smtp_host - SMTP_USERNAME: - from_secret: smtp_username - SMTP_PASSWORD: - from_secret: smtp_password - image: git.cryptic.systems/volker.raschek/drone-email:0.1.5 - when: - status: - - changed - - failure - -trigger: - branch: - - master - event: - - cron - - push - repo: - - volker.raschek/db-wait - ---- -kind: pipeline -type: docker -name: latest-arm64-v8 - -clone: - disable: true - -depends_on: -- linter - -platform: - os: linux - arch: arm64 - -steps: -- name: clone - image: git.cryptic.systems/volker.raschek/git:1.4.0 - -- name: build - image: docker.io/plugins/docker:20.18.8 - settings: - auto_tag: false - dockerfile: Dockerfile - force_tag: true - no_cache: true - purge: true - mirror: - from_secret: docker_io_mirror - registry: git.cryptic.systems - repo: git.cryptic.systems/volker.raschek/db-wait - tags: latest-arm64-v8 - username: - from_secret: git_cryptic_systems_container_registry_user - password: - from_secret: git_cryptic_systems_container_registry_password - -- name: email-notification - environment: - SMTP_FROM_ADDRESS: - from_secret: smtp_from_address - SMTP_FROM_NAME: - from_secret: smtp_from_name - SMTP_HOST: - from_secret: smtp_host - SMTP_USERNAME: - from_secret: smtp_username - SMTP_PASSWORD: - from_secret: smtp_password - image: git.cryptic.systems/volker.raschek/drone-email:0.1.5 - when: - status: - - changed - - failure - -trigger: - branch: - - master - event: - - cron - - push - repo: - - volker.raschek/db-wait - ---- -kind: pipeline -type: kubernetes -name: latest-manifest - -clone: - disable: true - -depends_on: -- latest-amd64 -- latest-arm64-v8 - -# docker.io/plugins/manifest only for amd64 architectures available -node_selector: - kubernetes.io/os: linux - kubernetes.io/arch: amd64 - -steps: -- name: clone - image: git.cryptic.systems/volker.raschek/git:1.4.0 - -- name: build-manifest - image: docker.io/plugins/manifest:1.4.0 - settings: - auto_tag: false - ignore_missing: true - spec: manifest.tmpl - username: - from_secret: git_cryptic_systems_container_registry_user - password: - from_secret: git_cryptic_systems_container_registry_password - -- name: email-notification - environment: - SMTP_FROM_ADDRESS: - from_secret: smtp_from_address - SMTP_FROM_NAME: - from_secret: smtp_from_name - SMTP_HOST: - from_secret: smtp_host - SMTP_USERNAME: - from_secret: smtp_username - SMTP_PASSWORD: - from_secret: smtp_password - image: git.cryptic.systems/volker.raschek/drone-email:0.1.5 - resources: - limits: - cpu: 150 - memory: 150M - when: - status: - - changed - - failure - -trigger: - branch: - - master - event: - - cron - - push - repo: - - volker.raschek/db-wait - ---- -kind: pipeline -type: kubernetes -name: latest-sync - -clone: - disable: true - -depends_on: -- latest-manifest - -steps: -- name: clone - image: git.cryptic.systems/volker.raschek/git:1.4.0 - -- name: latest-sync - commands: - - skopeo sync --all --src=docker --src-creds=$SRC_CRED_USERNAME:$SRC_CRED_PASSWORD --dest=docker --dest-creds=$DEST_CRED_USERNAME:$DEST_CRED_PASSWORD git.cryptic.systems/volker.raschek/db-wait docker.io/volkerraschek - environment: - SRC_CRED_USERNAME: - from_secret: git_cryptic_systems_container_registry_user - SRC_CRED_PASSWORD: - from_secret: git_cryptic_systems_container_registry_password - DEST_CRED_USERNAME: - from_secret: container_image_registry_user - DEST_CRED_PASSWORD: - from_secret: container_image_registry_password - image: quay.io/skopeo/stable:v1.18.0 - -- name: email-notification - environment: - SMTP_FROM_ADDRESS: - from_secret: smtp_from_address - SMTP_FROM_NAME: - from_secret: smtp_from_name - SMTP_HOST: - from_secret: smtp_host - SMTP_USERNAME: - from_secret: smtp_username - SMTP_PASSWORD: - from_secret: smtp_password - image: git.cryptic.systems/volker.raschek/drone-email:0.1.5 - resources: - limits: - cpu: 150 - memory: 150M - when: - status: - - changed - - failure - -trigger: - branch: - - master - event: - - cron - - push - repo: - - volker.raschek/db-wait - ---- -kind: pipeline -type: docker -name: tagged-amd64 - -clone: - disable: true - -platform: - os: linux - arch: amd64 - -steps: -- name: clone - image: git.cryptic.systems/volker.raschek/git:1.4.0 - -- name: build - image: docker.io/plugins/docker:20.18.8 - settings: - auto_tag: true - auto_tag_suffix: amd64 - dockerfile: Dockerfile - force_tag: true - no_cache: true - purge: true - mirror: - from_secret: docker_io_mirror - registry: git.cryptic.systems - repo: git.cryptic.systems/volker.raschek/db-wait - username: - from_secret: git_cryptic_systems_container_registry_user - password: - from_secret: git_cryptic_systems_container_registry_password - build_args: - - VERSION=${DRONE_TAG} - -- name: email-notification - environment: - SMTP_FROM_ADDRESS: - from_secret: smtp_from_address - SMTP_FROM_NAME: - from_secret: smtp_from_name - SMTP_HOST: - from_secret: smtp_host - SMTP_USERNAME: - from_secret: smtp_username - SMTP_PASSWORD: - from_secret: smtp_password - image: git.cryptic.systems/volker.raschek/drone-email:0.1.5 - when: - status: - - changed - - failure - -trigger: - event: - - tag - repo: - - volker.raschek/db-wait - ---- -kind: pipeline -type: docker -name: tagged-arm64-v8 - -clone: - disable: true - -platform: - os: linux - arch: arm64 - -steps: -- name: clone - image: git.cryptic.systems/volker.raschek/git:1.4.0 - -- name: build - image: docker.io/plugins/docker:20.18.8 - settings: - auto_tag: true - auto_tag_suffix: arm64-v8 - dockerfile: Dockerfile - force_tag: true - no_cache: true - purge: true - mirror: - from_secret: docker_io_mirror - registry: git.cryptic.systems - repo: git.cryptic.systems/volker.raschek/db-wait - username: - from_secret: git_cryptic_systems_container_registry_user - password: - from_secret: git_cryptic_systems_container_registry_password - build_args: - - VERSION=${DRONE_TAG} - -- name: email-notification - environment: - SMTP_FROM_ADDRESS: - from_secret: smtp_from_address - SMTP_FROM_NAME: - from_secret: smtp_from_name - SMTP_HOST: - from_secret: smtp_host - SMTP_USERNAME: - from_secret: smtp_username - SMTP_PASSWORD: - from_secret: smtp_password - image: git.cryptic.systems/volker.raschek/drone-email:0.1.5 - when: - status: - - changed - - failure - -trigger: - event: - - tag - repo: - - volker.raschek/db-wait - ---- -kind: pipeline -type: kubernetes -name: tagged-manifest - -clone: - disable: true - -depends_on: -- tagged-amd64 -- tagged-arm64-v8 - -# docker.io/plugins/manifest only for amd64 architectures available -node_selector: - kubernetes.io/os: linux - kubernetes.io/arch: amd64 - -steps: -- name: clone - image: git.cryptic.systems/volker.raschek/git:1.4.0 - -- name: build-manifest - image: docker.io/plugins/manifest:1.4.0 - settings: - auto_tag: true - ignore_missing: true - spec: manifest.tmpl - username: - from_secret: git_cryptic_systems_container_registry_user - password: - from_secret: git_cryptic_systems_container_registry_password - -- name: email-notification - environment: - SMTP_FROM_ADDRESS: - from_secret: smtp_from_address - SMTP_FROM_NAME: - from_secret: smtp_from_name - SMTP_HOST: - from_secret: smtp_host - SMTP_USERNAME: - from_secret: smtp_username - SMTP_PASSWORD: - from_secret: smtp_password - image: git.cryptic.systems/volker.raschek/drone-email:0.1.5 - resources: - limits: - cpu: 150 - memory: 150M - when: - status: - - changed - - failure - -trigger: - event: - - tag - repo: - - volker.raschek/db-wait - ---- -kind: pipeline -type: kubernetes -name: tagged-sync - -clone: - disable: true - -depends_on: -- tagged-manifest - -steps: -- name: clone - image: git.cryptic.systems/volker.raschek/git:1.4.0 - -- name: tagged-sync - commands: - - skopeo sync --all --src=docker --src-creds=$SRC_CRED_USERNAME:$SRC_CRED_PASSWORD --dest=docker --dest-creds=$DEST_CRED_USERNAME:$DEST_CRED_PASSWORD git.cryptic.systems/volker.raschek/db-wait docker.io/volkerraschek - environment: - SRC_CRED_USERNAME: - from_secret: git_cryptic_systems_container_registry_user - SRC_CRED_PASSWORD: - from_secret: git_cryptic_systems_container_registry_password - DEST_CRED_USERNAME: - from_secret: container_image_registry_user - DEST_CRED_PASSWORD: - from_secret: container_image_registry_password - image: quay.io/skopeo/stable:v1.18.0 - -- name: email-notification - environment: - SMTP_FROM_ADDRESS: - from_secret: smtp_from_address - SMTP_FROM_NAME: - from_secret: smtp_from_name - SMTP_HOST: - from_secret: smtp_host - SMTP_USERNAME: - from_secret: smtp_username - SMTP_PASSWORD: - from_secret: smtp_password - image: git.cryptic.systems/volker.raschek/drone-email:0.1.5 - resources: - limits: - cpu: 150 - memory: 150M - when: - status: - - changed - - failure - -trigger: - event: - - tag - repo: - - volker.raschek/db-wait diff --git a/.gitea/workflows/golang-tests.yaml b/.gitea/workflows/golang-tests.yaml new file mode 100644 index 0000000..c46ec77 --- /dev/null +++ b/.gitea/workflows/golang-tests.yaml @@ -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 diff --git a/.gitea/workflows/markdown-linters.yaml b/.gitea/workflows/markdown-linters.yaml new file mode 100644 index 0000000..e2715a7 --- /dev/null +++ b/.gitea/workflows/markdown-linters.yaml @@ -0,0 +1,20 @@ +name: Markdown linter + +on: + pull_request: + types: [ "opened", "reopened", "synchronize" ] + push: + branches: [ '**' ] + tags-ignore: [ '**' ] + workflow_dispatch: {} + +jobs: + markdown-lint: + container: + image: git.cryptic.systems/volker.raschek/markdownlint:0.45.0 + runs-on: + - ubuntu-latest + steps: + - uses: actions/checkout@v4.2.2 + - name: Lint Markdown files + run: markdownlint --config .markdownlint.yaml . \ No newline at end of file diff --git a/.gitea/workflows/release.yaml b/.gitea/workflows/release.yaml new file mode 100644 index 0000000..502f443 --- /dev/null +++ b/.gitea/workflows/release.yaml @@ -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/db-wait:${TAG} \ + docker://docker.io/volkerraschek/db-wait:${TAG} diff --git a/.gitea/workflows/update-docker-hub-description.yaml b/.gitea/workflows/update-docker-hub-description.yaml new file mode 100644 index 0000000..4040689 --- /dev/null +++ b/.gitea/workflows/update-docker-hub-description.yaml @@ -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/dcmerge + readme-filepath: README.md \ No newline at end of file diff --git a/.gitignore b/.gitignore index 7674379..33e3721 100644 --- a/.gitignore +++ b/.gitignore @@ -1,25 +1,3 @@ -**/*.iml -**/*.idea -**/target -**/.project -**/.settings -**/.classpath -**/npm-debug.log -**/node/* -**/nb-configuration.xml -**/*.war -**/*.class -**/*.DS_Store - -**/.vscode - -.repo -**/pom.xml.releaseBackup -**/release.properties -**/bindata.go -**/t1k.rpm -**/orbis-u-t1k.tar.gz -**/container.log -**/.env -**/coverage* -db-wait* \ No newline at end of file +db-wait +coverage.txt +dist \ No newline at end of file diff --git a/.golangci.yml b/.golangci.yml deleted file mode 100644 index 78a7d8a..0000000 --- a/.golangci.yml +++ /dev/null @@ -1,29 +0,0 @@ -run: - skip-dirs: - - it - timeout: 10m - tests: true - -linters: - disable-all: true - enable: - # Default - - deadcode - - errcheck - - gosimple - - govet - - ineffassign - - staticcheck - - structcheck - - typecheck - - unused - - varcheck - - # Additionally linters - - bodyclose - - misspell - - nilerr - - rowserrcheck - - sqlclosecheck - - unparam - - whitespace \ No newline at end of file diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 0000000..a8a2427 --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,175 @@ +project_name: db-wait + +archives: +- formats: [ "tar.xz" ] + files: + - README.md + - LICENSE + +before: + hooks: + - go mod tidy + +builds: +- main: main.go + binary: >- + {{ .ProjectName }}- + {{- .Version }}- + {{- .Os }}- + {{- if eq .Arch "amd64" }}amd64 + {{- else if eq .Arch "amd64_v1" }}amd64 + {{- else }}{{ .Arch }}{{ end }} + {{- if .Arm }}-{{ .Arm }}{{ end }} + env: + - CGO_ENABLED=0 + - GONOSUMDB={{ .Env.GONOSUMDB }} + - GOPROXY={{ .Env.GOPROXY }} + goos: + - linux + goarch: + - amd64 + - arm + - arm64 + - riscv64 + goarm: + - "6" + - "7" + flags: + - -trimpath + ldflags: + - -s -w -X 'main.version={{ trimprefix .Tag "v" }}' + +changelog: + filters: + exclude: + - '^chore' + - '^docs' + - '^test' + - Merge pull request + - Merge branch + - go mod tidy + format: "{{.SHA}}: {{.Message}} (@{{.AuthorUsername}})" + groups: + - title: Features + regexp: '^.*?feat(\([[:word:]]+\))??!?:.+$' + order: 0 + - title: "Bug fixes" + regexp: '^.*?fix(\([[:word:]]+\))??!?:.+$' + order: 1 + - title: Others + order: 999 + sort: asc + use: git + +dockers: +- build_flag_templates: + - --label=org.opencontainers.image.created={{ time "2006-01-02T15:04:05Z07:00" }} + - --label=org.opencontainers.image.description={{ .ProjectName }} + - --label=org.opencontainers.image.documentation={{ .ProjectName }} + - --label=org.opencontainers.image.revision={{ .FullCommit }} + - --label=org.opencontainers.image.source={{ .GitURL }} + - --label=org.opencontainers.image.title={{ .ProjectName }} + - --label=org.opencontainers.image.url=https://git.cryptic.systems/volker.raschek/{{ .ProjectName }} + - --label=org.opencontainers.image.version={{ trimprefix .Tag "v" }} + - --platform=linux/amd64 + - --pull + dockerfile: Dockerfile + goarch: amd64 + goos: linux + image_templates: + - 'git.cryptic.systems/volker.raschek/{{ .ProjectName }}:{{ trimprefix .Tag "v" }}-amd64' + skip_push: false + use: buildx + +- build_flag_templates: + - --label=org.opencontainers.image.created={{ time "2006-01-02T15:04:05Z07:00" }} + - --label=org.opencontainers.image.description={{ .ProjectName }} + - --label=org.opencontainers.image.documentation={{ .ProjectName }} + - --label=org.opencontainers.image.revision={{ .FullCommit }} + - --label=org.opencontainers.image.source={{ .GitURL }} + - --label=org.opencontainers.image.title={{ .ProjectName }} + - --label=org.opencontainers.image.url=https://git.cryptic.systems/volker.raschek/{{ .ProjectName }} + - --label=org.opencontainers.image.version={{ trimprefix .Tag "v" }} + - --platform=linux/arm/v6 + - --pull + dockerfile: Dockerfile + goarch: arm + goarm: "6" + goos: linux + image_templates: + - 'git.cryptic.systems/volker.raschek/{{ .ProjectName }}:{{ trimprefix .Tag "v" }}-arm-v6' + skip_push: false + use: buildx + +- build_flag_templates: + - --label=org.opencontainers.image.created={{ time "2006-01-02T15:04:05Z07:00" }} + - --label=org.opencontainers.image.description={{ .ProjectName }} + - --label=org.opencontainers.image.documentation={{ .ProjectName }} + - --label=org.opencontainers.image.revision={{ .FullCommit }} + - --label=org.opencontainers.image.source={{ .GitURL }} + - --label=org.opencontainers.image.title={{ .ProjectName }} + - --label=org.opencontainers.image.url=https://git.cryptic.systems/volker.raschek/{{ .ProjectName }} + - --label=org.opencontainers.image.version={{ trimprefix .Tag "v" }} + - --platform=linux/arm/v7 + - --pull + dockerfile: Dockerfile + goarch: arm + goarm: "7" + goos: linux + image_templates: + - 'git.cryptic.systems/volker.raschek/{{ .ProjectName }}:{{ trimprefix .Tag "v" }}-arm-v7' + skip_push: false + use: buildx + +- build_flag_templates: + - --label=org.opencontainers.image.created={{ time "2006-01-02T15:04:05Z07:00" }} + - --label=org.opencontainers.image.description={{ .ProjectName }} + - --label=org.opencontainers.image.documentation={{ .ProjectName }} + - --label=org.opencontainers.image.revision={{ .FullCommit }} + - --label=org.opencontainers.image.source={{ .GitURL }} + - --label=org.opencontainers.image.title={{ .ProjectName }} + - --label=org.opencontainers.image.url=https://git.cryptic.systems/volker.raschek/{{ .ProjectName }} + - --label=org.opencontainers.image.version={{ trimprefix .Tag "v" }} + - --platform=linux/arm64 + - --pull + dockerfile: Dockerfile + goarch: arm64 + goos: linux + image_templates: + - 'git.cryptic.systems/volker.raschek/{{ .ProjectName }}:{{ trimprefix .Tag "v" }}-arm64' + skip_push: false + use: buildx + +- build_flag_templates: + - --label=org.opencontainers.image.created={{ time "2006-01-02T15:04:05Z07:00" }} + - --label=org.opencontainers.image.description={{ .ProjectName }} + - --label=org.opencontainers.image.documentation={{ .ProjectName }} + - --label=org.opencontainers.image.revision={{ .FullCommit }} + - --label=org.opencontainers.image.source={{ .GitURL }} + - --label=org.opencontainers.image.title={{ .ProjectName }} + - --label=org.opencontainers.image.url=https://git.cryptic.systems/volker.raschek/{{ .ProjectName }} + - --label=org.opencontainers.image.version={{ trimprefix .Tag "v" }} + - --platform=linux/riscv64 + - --pull + dockerfile: Dockerfile + goarch: riscv64 + goos: linux + image_templates: + - 'git.cryptic.systems/volker.raschek/{{ .ProjectName }}:{{ trimprefix .Tag "v" }}-riscv64' + skip_push: false + use: buildx + +docker_manifests: +- name_template: 'git.cryptic.systems/volker.raschek/{{ .ProjectName }}:{{ trimprefix .Tag "v" }}' + image_templates: + - 'git.cryptic.systems/volker.raschek/{{ .ProjectName }}:{{ trimprefix .Tag "v" }}-amd64' + - 'git.cryptic.systems/volker.raschek/{{ .ProjectName }}:{{ trimprefix .Tag "v" }}-arm-v6' + - 'git.cryptic.systems/volker.raschek/{{ .ProjectName }}:{{ trimprefix .Tag "v" }}-arm-v7' + - 'git.cryptic.systems/volker.raschek/{{ .ProjectName }}:{{ trimprefix .Tag "v" }}-arm64' + - 'git.cryptic.systems/volker.raschek/{{ .ProjectName }}:{{ trimprefix .Tag "v" }}-riscv64' + +gitea_urls: + api: https://git.cryptic.systems/api/v1 + download: https://git.cryptic.systems + +version: 2 diff --git a/.markdownlint.yaml b/.markdownlint.yaml index 4e6e709..34c4081 100644 --- a/.markdownlint.yaml +++ b/.markdownlint.yaml @@ -45,19 +45,17 @@ MD012: # MD013/line-length - Line length MD013: # Number of characters - line_length: 80 + line_length: 120 # Number of characters for headings - heading_line_length: 80 + heading_line_length: 120 # Number of characters for code blocks - code_block_line_length: 80 + code_block_line_length: 120 # Include code blocks code_blocks: false # Include tables tables: false # Include headings headings: true - # Include headings - headers: true # Strict length checking strict: false # Stern length checking @@ -70,11 +68,6 @@ MD022: # Blank lines below heading lines_below: 1 -# MD024/no-duplicate-heading/no-duplicate-header - Multiple headings with the same content -MD024: - # Only check sibling headings - allow_different_nesting: true - # MD025/single-title/single-h1 - Multiple top-level headings in the same document MD025: # Heading level @@ -128,8 +121,7 @@ MD041: # MD044/proper-names - Proper names should have the correct capitalization MD044: # List of proper names - names: - - oas-collector + names: [] # Include code blocks code_blocks: false @@ -141,4 +133,4 @@ MD046: # MD048/code-fence-style - Code fence style MD048: # Code fence syle - style: "backtick" \ No newline at end of file + style: "backtick" diff --git a/Dockerfile b/Dockerfile index 4a24b3f..002ffae 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,27 +1,5 @@ -FROM docker.io/library/golang:1.22.3-alpine3.18 AS build +FROM docker.io/library/alpine:3.22.0 -ARG VERSION=latest - -COPY . /workspace - -WORKDIR /workspace - -RUN set -ex && \ - apk update && \ - apk add git make && \ - make install VERSION=${VERSION} DESTDIR=/db-wait PREFIX=/usr - -FROM docker.io/library/alpine:3.21 - -ARG VERSION=latest - -LABEL org.opencontainers.image.authors="Markus Pesch" \ - org.opencontainers.image.description="Wait until database is ready for handling connections" \ - org.opencontainers.image.documentation="https://git.cryptic.systems/volker.raschek/db-wait#db-wait" \ - org.opencontainers.image.title="db-wait" \ - org.opencontainers.image.vendor="Markus Pesch" \ - org.opencontainers.image.version="${VERSION}" - -COPY --from=build /db-wait / +COPY db-wait-* /usr/bin/db-wait ENTRYPOINT [ "/usr/bin/db-wait" ] diff --git a/Makefile b/Makefile index f51069a..6973ec7 100644 --- a/Makefile +++ b/Makefile @@ -1,50 +1,58 @@ -VERSION?=$(shell git describe --abbrev=0)+$(shell date +'%Y%m%d%H%I%S') - -EXECUTABLE:=db-wait +EXECUTABLE=db-wait +VERSION?=$(shell git describe --abbrev=0)+hash.$(shell git rev-parse --short HEAD) +# Destination directory and prefix to place the compiled binaries, documentaions +# and other files. DESTDIR?= PREFIX?=/usr/local -# BINARIES -# ============================================================================== -all: ${EXECUTABLE} +# 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 image. +CONTAINER_RUNTIME?=$(shell which podman) -${EXECUTABLE}: +# DB_WAIT_IMAGE_REGISTRY_NAME +# Defines the name of the new container to be built using several variables. +DB_WAIT_IMAGE_REGISTRY_NAME:=git.cryptic.systems +DB_WAIT_IMAGE_REGISTRY_USER:=volker.raschek + +DB_WAIT_IMAGE_NAMESPACE?=${DB_WAIT_IMAGE_REGISTRY_USER} +DB_WAIT_IMAGE_NAME:=${EXECUTABLE} +DB_WAIT_IMAGE_VERSION?=latest +DB_WAIT_IMAGE_FULLY_QUALIFIED=${DB_WAIT_IMAGE_REGISTRY_NAME}/${DB_WAIT_IMAGE_NAMESPACE}/${DB_WAIT_IMAGE_NAME}:${DB_WAIT_IMAGE_VERSION} + +# BIN +# ============================================================================== +db-wait: + CGO_ENABLED=1 \ GOPROXY=$(shell go env GOPROXY) \ - GOPRIVATE=$(shell go env GOPRIVATE) \ - go build -ldflags "-X main.version=${VERSION:v%=%}" -o ${@} - -# UN/INSTALL -# ============================================================================== -PHONY+=install -install: ${EXECUTABLE} - install --directory ${DESTDIR}${PREFIX}/bin - install --mode 755 ${EXECUTABLE} ${DESTDIR}${PREFIX}/bin/${EXECUTABLE} - - install --directory ${DESTDIR}${PREFIX}/licenses/${EXECUTABLE} - install --mode 644 LICENSE ${DESTDIR}${PREFIX}/licenses/${EXECUTABLE}/LICENSE - -PHONY+=uninstall -uninstall: - -rm --recursive --force \ - ${DESTDIR}${PREFIX}/bin/${EXECUTABLE} \ - ${DESTDIR}${PREFIX}/licenses/${EXECUTABLE}/LICENSE + go build -ldflags "-X 'main.version=${VERSION}'" -o ${@} main.go # CLEAN # ============================================================================== PHONY+=clean clean: - rm --force --recursive ${EXECUTABLE}* || true + rm --force --recursive db-wait -# TEST +# TESTS # ============================================================================== PHONY+=test/unit test/unit: - go test -v -race -coverprofile=coverage.txt -covermode=atomic -timeout 600s -count=1 ./pkg/... + 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 - go tool cover -html=coverage.txt + CGO_ENABLED=0 \ + GOPROXY=$(shell go env GOPROXY) \ + go tool cover -html=coverage.txt # GOLANGCI-LINT # ============================================================================== @@ -52,11 +60,52 @@ PHONY+=golangci-lint golangci-lint: golangci-lint run --concurrency=$(shell nproc) -# GOSEC +# INSTALL # ============================================================================== -PHONY+=gosec -gosec: - gosec $(shell pwd)/... +PHONY+=uninstall +install: db-wait + install --directory ${DESTDIR}/etc/bash_completion.d + ./db-wait 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 VERSION=${VERSION} \ + --file Dockerfile \ + --no-cache \ + --pull \ + --tag ${DB_WAIT_IMAGE_FULLY_QUALIFIED} \ + . + +# DELETE CONTAINER IMAGE +# ============================================================================== +PHONY:=container-image/delete +container-image/delete: + - ${CONTAINER_RUNTIME} image rm ${DB_WAIT_IMAGE_FULLY_QUALIFIED} + +# PUSH CONTAINER IMAGE +# ============================================================================== +PHONY+=container-image/push +container-image/push: + echo ${DB_WAIT_IMAGE_REGISTRY_PASSWORD} | ${CONTAINER_RUNTIME} login ${DB_WAIT_IMAGE_REGISTRY_NAME} --username ${DB_WAIT_IMAGE_REGISTRY_USER} --password-stdin + ${CONTAINER_RUNTIME} push ${DB_WAIT_IMAGE_FULLY_QUALIFIED} # PHONY # ============================================================================== diff --git a/README.md b/README.md index 2815f5c..5137402 100644 --- a/README.md +++ b/README.md @@ -1,21 +1,18 @@ # db-wait -[![Build Status](https://drone.cryptic.systems/api/badges/volker.raschek/db-wait/status.svg)](https://drone.cryptic.systems/volker.raschek/db-wait) [![Docker Pulls](https://img.shields.io/docker/pulls/volkerraschek/db-wait)](https://hub.docker.com/r/volkerraschek/db-wait) -With `db-wait` is it possible to wait in CI/CD environments until a database -connection can be established and SQL queries are possible. +With `db-wait` is it possible to wait in CI/CD environments until a database connection can be established and SQL +queries are possible. -This is very useful for example when a database is started for an integration -test and it needs time to start and initialize all schemes before the test -connects to it. +This is very useful for example when a database is started for an integration test and it needs time to start and +initialize all schemes before the test connects to it. ## Usage -As argument db-wait expects a database URI. This can be different depending on -the backend. Currently only oracle and postgres are supported. The supported URI -patterns can be found in the respective library or directly in the documentation -of the database backend. +As argument db-wait expects a database URI. This can be different depending on the backend. Currently only oracle and +postgres are supported. The supported URI patterns can be found in the respective library or directly in the +documentation of the database backend. For example: @@ -28,15 +25,14 @@ db-wait oracle://user:password@localhost:1521/xe ``` More about URI Pattern is documented here for -[oracle](https://godror.github.io/godror/doc/connection.html#-connection-strings) -and +[oracle](https://godror.github.io/godror/doc/connection.html#-connection-strings) and [postgres](https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING). ## Installation -There are two ways to install `db-wait`. Directly via `go` or via `make` in -combination with `git` and `go`. The advantage of the second option is that the -binary is installed with all the additional files that the developer specifies. +There are two ways to install `db-wait`. Directly via `go` or via `make` in combination with `git` and `go`. The +advantage of the second option is that the binary is installed with all the additional files that the developer +specifies. ```bash # go @@ -50,15 +46,14 @@ $ git clone https://git.cryptic.systems/volker.raschek/db-wait.git && \ ## Usage as container image -Alternatively can be `db-wait` used as container image. A local installation is -not necessary. +Alternatively can be `db-wait` used as container image. A local installation is not necessary. ```bash # postgres -$ docker run --rm --network host docker.io/volkerraschek/db-wait:latest \ +$ docker run --rm --network host git.cryptic.systems/volker.raschek/db-wait:latest \ postgres://user:password@localhost:5432/postgres?sslmode=disable # oracle -$ docker run --rm --network host docker.io/volkerraschek/db-wait:latest \ +$ docker run --rm --network host git.cryptic.systems/volker.raschek/db-wait:latest \ oracle://user:password@localhost:1521/xe ``` diff --git a/go.mod b/go.mod index 31b1b34..8353543 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module git.cryptic.systems/volker.raschek/db-wait -go 1.17 +go 1.24 require ( github.com/lib/pq v1.10.9 diff --git a/manifest.tmpl b/manifest.tmpl deleted file mode 100644 index 5c7313c..0000000 --- a/manifest.tmpl +++ /dev/null @@ -1,20 +0,0 @@ -image: git.cryptic.systems/volker.raschek/db-wait:{{#if build.tag}}{{trimPrefix "v" build.tag}}{{else}}latest{{/if}} -{{#if build.tags}} -tags: -{{#each build.tags}} - - {{this}} -{{/each}} - - "latest" -{{/if}} -manifests: - - - image: git.cryptic.systems/volker.raschek/db-wait:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{else}}latest{{/if}}-amd64 - platform: - architecture: amd64 - os: linux - - - image: git.cryptic.systems/volker.raschek/db-wait:{{#if build.tag}}{{trimPrefix "v" build.tag}}{{else}}latest{{/if}}-arm64-v8 - platform: - architecture: arm64 - os: linux - variant: v8 \ No newline at end of file diff --git a/pkg/dbwait/dbwait.go b/pkg/dbwait/dbwait.go index 1485e3e..8c4b366 100644 --- a/pkg/dbwait/dbwait.go +++ b/pkg/dbwait/dbwait.go @@ -25,7 +25,7 @@ func Wait(databaseURL *url.URL, period time.Duration, timeout time.Duration) err return err } } - defer sqlDB.Close() + defer func() { _ = sqlDB.Close() }() ctx, cancel := context.WithTimeout(context.Background(), timeout) defer cancel() @@ -63,12 +63,15 @@ LOOP: return nil case "postgres": row := sqlDB.QueryRowContext(queryCtx, "SELECT 1 AS ROW") - if row.Err() != nil { + err := row.Err() + switch { + case err == nil: + return nil + default: fmt.Fprintf(os.Stderr, "%s: %s\n", time.Now().String(), err.Error()) ticker.Reset(period) continue LOOP } - return nil } } }