From 5aa1e4efcbb47267cbd9e6f139162694b33d59e4 Mon Sep 17 00:00:00 2001 From: Vladimir Hodakov Date: Tue, 14 Jan 2025 02:32:01 +0400 Subject: [PATCH] Try to build :latest using docker-dind --- .woodpecker/build.yaml | 35 +++++++++++++++++ .woodpecker/docker.yaml | 40 -------------------- .woodpecker/tag.yaml | 17 +++++++++ scripts/semver.sh | 83 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 135 insertions(+), 40 deletions(-) create mode 100644 .woodpecker/build.yaml delete mode 100644 .woodpecker/docker.yaml create mode 100644 .woodpecker/tag.yaml create mode 100755 scripts/semver.sh diff --git a/.woodpecker/build.yaml b/.woodpecker/build.yaml new file mode 100644 index 0000000..e9b1fd8 --- /dev/null +++ b/.woodpecker/build.yaml @@ -0,0 +1,35 @@ +matrix: + platform: + - linux/amd64 + - linux/arm64 + +labels: + platform: ${platform} + +when: + branch: main + event: [push, pull_request, tag] + +steps: + test-build: + image: docker:27-dind + commands: + - docker build -t source.hodakov.me/hdkv/phpbb:${CI_COMMIT_SHA:0:10}-${platform} . + volumes: + - /var/run/docker.sock:/var/run/docker.sock + when: + event: pull_request + + build-to-registry: + image: docker:27-dind + environment: + CI_USER_PASSWORD: + from_secret: registry_token + commands: + - docker login -u ${CI_REPO_OWNER} -p $${CI_USER_PASSWORD} source.hodakov.me + - docker build -t source.hodakov.me/hdkv/phpbb:${CI_COMMIT_SHA:0:10}-${platform} . + - docker push source.hodakov.me/hdkv/phpbb:${CI_COMMIT_SHA:0:10}-${platform} + volumes: + - /var/run/docker.sock:/var/run/docker.sock + when: + event: [push, tag] diff --git a/.woodpecker/docker.yaml b/.woodpecker/docker.yaml deleted file mode 100644 index 4dc6595..0000000 --- a/.woodpecker/docker.yaml +++ /dev/null @@ -1,40 +0,0 @@ -matrix: - platform: - - linux/amd64 - - linux/arm64 - -labels: - platform: ${platform} - -when: - branch: main - event: [push, pull_request, tag] - -variables: - - &repo source.hodakov.me/${CI_REPO_OWNER}/phpbb - -steps: - test-build: - image: woodpeckerci/plugin-docker-buildx:5.1.0 - privileged: true - settings: - dockerfile: Dockerfile - dry_run: true - repo: *repo - auto_tag: true - when: - event: pull_request - - publish: - image: woodpeckerci/plugin-docker-buildx:5.1.0 - privileged: true - settings: - dockerfile: Dockerfile - repo: *repo - registry: source.hodakov.me - auto_tag: true - username: ${CI_REPO_OWNER} - password: - from_secret: registry_token - when: - event: [push, tag] diff --git a/.woodpecker/tag.yaml b/.woodpecker/tag.yaml new file mode 100644 index 0000000..338f526 --- /dev/null +++ b/.woodpecker/tag.yaml @@ -0,0 +1,17 @@ +when: + branch: main + event: [push, tag] + +depends_on: + - build + +steps: + tag: + image: docker:27-dind + commands: + - docker pull source.hodakov.me/hdkv/phpbb:${CI_COMMIT_SHA:0:10}-amd64 + - docker pull source.hodakov.me/hdkv/phpbb:${CI_COMMIT_SHA:0:10}-arm64 + - docker manifest create source.hodakov.me/hdkv/phpbb:latest source.hodakov.me/hdkv/phpbb:${CI_COMMIT_SHA:0:10}-amd64 source.hodakov.me/hdkv/phpbb:${CI_COMMIT_SHA:0:10}-arm64 + - docker manifest push source.hodakov.me/hdkv/phpbb:latest + volumes: + - /var/run/docker.sock:/var/run/docker.sock diff --git a/scripts/semver.sh b/scripts/semver.sh new file mode 100755 index 0000000..a074d3c --- /dev/null +++ b/scripts/semver.sh @@ -0,0 +1,83 @@ +#!/bin/bash -eu + +# This script prints out git metadata information for a given commit (or head by default) +# It assumes tags of the form `v1.2.3`, and will print prerelease versions when +# not on an exact tag. +# +# It is intended to be used like so: +# +# cd +# $(../semver-from-git.sh) +# +# or +# +# $(../semver-from-git.sh ) +# +# For prerelease, it prints: +# +# export GIT_BRANCH="master" +# export GIT_SEMVER_FROM_TAG="1.0.1-master+3.ge675710" +# +# where GIT_BRANCH is the first branch it finds with the given commit, and the version string is: +# ..-+. +# +# When on an exact tag, it prints: +# +# export GIT_BRANCH="master" +# export GIT_EXACT_TAG=v1.0.2 +# export GIT_SEMVER_FROM_TAG=1.0.2 +# +# When the working tree is dirty, it will also put ".SNAPSHOT." on the end of the version +# This is useful if someone has deployed something from their local machine. + +# (C) Timothy Jones, 2019, released under BSD License 2.0 (3-clause BSD license) +# https://github.com/TimothyJones + +if [ -z "${1:-}" ]; then + COMMIT="HEAD" + + # Test whether the working tree is dirty or not + if [ -z "$(git status -s)" ]; then + STATUS="" + else + STATUS=".SNAPSHOT.$(hostname -s)" + fi +else + COMMIT="$1" + STATUS="" # When looking at an exact commit, the working tree is irrelevant +fi + +DESCRIBE=$(git describe --always --tags "$COMMIT") +VERSION=$(echo "$DESCRIBE" | sed 's/\(.*\)-\(.*\)-g\(.*\)/\1+\2.\3/' | sed 's/v\(.*\)/\1/') +BRANCH=$(git branch --contains "$COMMIT" | grep -e "^\*" | sed 's/^\* //') + +echo "export GIT_BRANCH=$BRANCH" +export GIT_BRANCH=$BRANCH + +EXACT_TAG=$(git describe --always --exact-match --tags "$COMMIT" 2> /dev/null || true) +if [ ! -z "$EXACT_TAG" ] ; then + echo "export GIT_EXACT_TAG=${EXACT_TAG}" + echo "export GIT_SEMVER_FROM_TAG=$VERSION$STATUS" + export GIT_EXACT_TAG=${EXACT_TAG} + export GIT_SEMVER_FROM_TAG=$VERSION$STATUS +else + # We split up the prefix and suffix so that we don't accidentally + # give sed commands via the branch name + PREFIX="$(echo "$VERSION" | sed 's/\(.*\)\(\+.*\)/\1/')" + SUFFIX="$(echo "$VERSION" | sed 's/\(.*\)\(\+.*\)/\2/')" + if [ -z $(echo "$PREFIX" | grep "-") ]; then + echo "export GIT_SEMVER_FROM_TAG=$PREFIX-$BRANCH""$SUFFIX$STATUS" + export GIT_SEMVER_FROM_TAG=$PREFIX-$BRANCH""$SUFFIX$STATUS + else + echo "export GIT_SEMVER_FROM_TAG=$PREFIX.$BRANCH""$SUFFIX$STATUS" + export GIT_SEMVER_FROM_TAG=$PREFIX.$BRANCH""$SUFFIX$STATUS + fi +fi + +### Add docker tags +echo "export DOCKER_EXACT_TAG=${GIT_EXACT_TAG/v}" +export DOCKER_EXACT_TAG=${GIT_EXACT_TAG/v} +echo "export DOCKER_MAJOR_TAG=${DOCKER_EXACT_TAG%.*.*}" +export DOCKER_MAJOR_TAG=${DOCKER_EXACT_TAG%.*.*} +echo "export DOCKER_MINOR_TAG=${DOCKER_EXACT_TAG%.*}" +export DOCKER_MINOR_TAG=${DOCKER_EXACT_TAG%.*}