From 7afb9b9b041304948c2d9b18c671a20d0f1ee333 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Fri, 12 Jan 2024 22:13:24 +0100 Subject: [PATCH] Init pipeline (#3) --- .gitignore | 4 ++ .pre-commit-config.yaml | 44 +++++++++++++++++++++ .woodpecker/release.yaml | 14 +++++++ .woodpecker/test-release.yaml | 72 +++++++++++++++++++++++++++++++++++ .yamllint.yaml | 9 +++++ README.md | 10 ++--- plugin.sh | 4 +- 7 files changed, 150 insertions(+), 7 deletions(-) create mode 100644 .pre-commit-config.yaml create mode 100644 .woodpecker/release.yaml create mode 100644 .woodpecker/test-release.yaml create mode 100644 .yamllint.yaml diff --git a/.gitignore b/.gitignore index f276527..cdd9512 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,7 @@ # kaniko base image cache files sha256:* + +# ide files +.vscode +.idea diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..ff0c289 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,44 @@ +repos: + - repo: meta + hooks: + - id: check-hooks-apply + - id: check-useless-excludes + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.5.0 + hooks: + - id: end-of-file-fixer + - id: trailing-whitespace + - repo: https://github.com/mrtazz/checkmake + rev: 0.2.2 + hooks: + - id: checkmake + - repo: https://github.com/hadolint/hadolint + rev: v2.12.1-beta + hooks: + - id: hadolint + - repo: https://github.com/adrienverge/yamllint.git + rev: v1.33.0 + hooks: + - id: yamllint + args: [--strict, -c=.yamllint.yaml] + - repo: local + hooks: + - id: yaml-file-extension + name: Check if YAML files has *.yaml extension. + entry: YAML filenames must have .yaml extension. + language: fail + files: .yml$ + exclude: '^.gitpod.yml$' + +ci: + autofix_commit_msg: | + [pre-commit.ci] auto fixes from pre-commit.com hooks [CI SKIP] + + for more information, see https://pre-commit.ci + autofix_prs: true + autoupdate_branch: '' + autoupdate_commit_msg: '[pre-commit.ci] pre-commit autoupdate' + autoupdate_schedule: monthly + # NB: hadolint not included in pre-commit.ci + skip: [check-hooks-apply, check-useless-excludes, hadolint] + submodules: false diff --git a/.woodpecker/release.yaml b/.woodpecker/release.yaml new file mode 100644 index 0000000..b96b463 --- /dev/null +++ b/.woodpecker/release.yaml @@ -0,0 +1,14 @@ +when: + event: push + branch: ${CI_REPO_DEFAULT_BRANCH} + +steps: + release: + image: woodpeckerci/plugin-ready-release-go:1.0.3 + pull: true + settings: + release_branch: ${CI_REPO_DEFAULT_BRANCH} + forge_type: github + git_email: woodpecker-bot@obermui.de + github_token: + from_secret: GITHUB_TOKEN diff --git a/.woodpecker/test-release.yaml b/.woodpecker/test-release.yaml new file mode 100644 index 0000000..3e24fd5 --- /dev/null +++ b/.woodpecker/test-release.yaml @@ -0,0 +1,72 @@ +when: + - event: pull_request + - event: tag + - event: push + branch: + - ${CI_REPO_DEFAULT_BRANCH} + - renovate/* + +variables: + - &platforms 'linux/amd64,linux/arm64,linux/s390x' + # vars used on push / tag events only + - publish_logins: &publish_logins + # Default DockerHub login + - registry: https://index.docker.io/v1/ + username: + from_secret: docker_username + password: + from_secret: docker_password + # Additional Quay.IO login + - registry: https://quay.io + username: + from_secret: QUAY_IO_USER + password: + from_secret: QUAY_IO_TOKEN + - &publish_repos 'docker.io/woodpeckerci/plugin-kaniko,quay.io/woodpeckerci/plugin-kaniko' + +steps: + lint: + image: alpine:3.19 + commands: + - apk add -U shellcheck + - shellcheck -e SC3040 -e SC3010 -e SC3037 -e SC2086 -e SC2166 -e SC2002 -e SC2236 -e SC3020 -e SC2162 *.sh + + # TODO: add test of fresh build kaniko + + build-dryrun: + image: woodpeckerci/plugin-docker-buildx:2.3.0 + depends_on: + - lint + settings: + repo: test/repo + dry_run: true + platforms: *platforms + tags: latest + when: + - event: pull_request + - event: push + branch: renovate/* + + release-next: + image: woodpeckerci/plugin-docker-buildx:2.3.0 + settings: + repo: *publish_repos + platforms: *platforms + tags: next + logins: *publish_logins + when: + branch: ${CI_REPO_DEFAULT_BRANCH} + event: push + + release-tag: + image: woodpeckerci/plugin-docker-buildx:2.3.0 + depends_on: vendor + settings: + repo: *publish_repos + platforms: *platforms + auto_tag: true + # remove line below if you can read it on a release branch and it's not the latest release branch + tags: latest + logins: *publish_logins + when: + event: tag diff --git a/.yamllint.yaml b/.yamllint.yaml new file mode 100644 index 0000000..8a65c5c --- /dev/null +++ b/.yamllint.yaml @@ -0,0 +1,9 @@ +extends: default + +ignore-from-file: + - .gitignore + +rules: + line-length: disable + document-start: disable + comments: disable diff --git a/README.md b/README.md index f8fc7c3..7516a14 100644 --- a/README.md +++ b/README.md @@ -58,15 +58,15 @@ steps: - name: build image: golang commands: - - go get + - go get - go build - make versiontags > .tags - name: publish image: banzaicloud/drone-kaniko settings: - registry: registry.example.com + registry: registry.example.com repo: registry.example.com/example-project - # tags: ${DRONE_COMMIT_SHA} <= it must be left undefined + # tags: ${DRONE_COMMIT_SHA} <= it must be left undefined username: from_secret: docker-username password: @@ -85,12 +85,12 @@ steps: - name: build image: golang commands: - - go get + - go get - go build - name: publish image: banzaicloud/drone-kaniko settings: - registry: registry.example.com + registry: registry.example.com repo: registry.example.com/example-project auto_tag: true # higher priority then .tags file # tags: ${DRONE_COMMIT_SHA} <= it must be left undefined to use auto_tag diff --git a/plugin.sh b/plugin.sh index 0d3e371..16b4fe7 100755 --- a/plugin.sh +++ b/plugin.sh @@ -2,12 +2,12 @@ set -euo pipefail -export PATH=$PATH:/kaniko/ +export PATH="$PATH:/kaniko/" REGISTRY=${PLUGIN_REGISTRY:-index.docker.io} if [ "${PLUGIN_USERNAME:-}" ] || [ "${PLUGIN_PASSWORD:-}" ]; then - DOCKER_AUTH=`echo -n "${PLUGIN_USERNAME}:${PLUGIN_PASSWORD}" | base64 | tr -d "\n"` + DOCKER_AUTH=$(echo -n "${PLUGIN_USERNAME}:${PLUGIN_PASSWORD}" | base64 | tr -d "\n") cat > /kaniko/.docker/config.json <