Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Merge pull request #20248 from opf/maintenance/daily-docker-release-builds

Cyril Rohr7ba86234aa94
diff --git a/.github/workflows/docker-release.yml b/.github/workflows/docker-release.yml
new file mode 100644
index 00000000000..f3ed1d66f33
--- /dev/null
+++ b/.github/workflows/docker-release.yml
@@ -0,0 +1,71 @@
+name: Docker / Tagged builds
+
+on:
+ push:
+ tags:
+ - v*
+ workflow_dispatch:
+ inputs:
+ tag:
+ description: "The tag to release. Note that this happens by default on the tag push. Only run this action when something went wrong!"
+ required: false
+
+jobs:
+ compute-inputs:
+ runs-on: ubuntu-latest
+ outputs:
+ tag: ${{ steps.compute.outputs.tag }}
+ branch: ${{ steps.compute.outputs.branch }}
+ steps:
+ - name: Checkout
+ uses: actions/checkout@v5
+ with:
+ ref: ${{ github.ref }}
+ - name: Compute tags and branch
+ id: compute
+ run: |
+ if [[ ${{ github.event_name }} == 'push' ]]; then
+ # Tag push e.g. refs/tags/v16.3.0 => v16.3.0
+ TAG_REF="${GITHUB_REF#refs/tags/}"
+ BRANCH_REF="$GITHUB_REF"
+ elif [[ ${{ github.event_name }} == 'workflow_dispatch' && -n "${{ inputs.tag }}" ]]; then
+ # Manual dispatch with tag
+ TAG_REF="${{ inputs.tag }}"
+ BRANCH_REF="${{ inputs.tag }}"
+ else
+ # Fallback to dev
+ TAG_REF="dev"
+ BRANCH_REF="dev"
+ fi
+
+ echo "branch=$BRANCH_REF" >> "$GITHUB_OUTPUT"
+ echo "tag=$TAG_REF" >> "$GITHUB_OUTPUT"
+
+ build:
+ needs: compute-inputs
+ uses: ./.github/workflows/docker.yml
+ with:
+ branch: ${{ needs.compute-inputs.outputs.branch }}
+ tag: ${{ needs.compute-inputs.outputs.tag }}
+ secrets: inherit
+
+ trigger_helm_release:
+ if: ${{ github.repository == 'opf/openproject' }}
+ needs: [compute-inputs, build]
+ permissions:
+ contents: none
+ runs-on: ubuntu-latest
+ steps:
+ - name: Trigger Helm charts release
+ env:
+ TOKEN: ${{ secrets.OPENPROJECT_CI_TOKEN }}
+ REPOSITORY: opf/helm-charts
+ WORKFLOW_ID: core_release.yml
+ run: |
+ # FIXME: re-enable once workflows are confirmed to be doing the right thing
+ echo "Would have triggered helm charts release with tag: ${{ needs.compute-inputs.outputs.tag }}"
+ exit 0
+ curl -i --fail-with-body -H"authorization: Bearer $TOKEN" \
+ -XPOST -H"Accept: application/vnd.github.v3+json" \
+ https://api.github.com/repos/$REPOSITORY/actions/workflows/$WORKFLOW_ID/dispatches \
+ -d '{"ref": "main", "inputs": { "tag" : "${{ needs.compute-inputs.outputs.tag }}" }}'
\ No newline at end of file
diff --git a/.github/workflows/docker-scheduled.yml b/.github/workflows/docker-scheduled.yml
new file mode 100644
index 00000000000..102e391a601
--- /dev/null
+++ b/.github/workflows/docker-scheduled.yml
@@ -0,0 +1,30 @@
+name: Docker / Scheduled builds
+
+on:
+ # build dev and release branches daily
+ schedule:
+ - cron: "20 2 * * *" # Daily at 02:20
+ workflow_dispatch: # Allow manual trigger
+
+jobs:
+ generate-matrix:
+ runs-on: ubuntu-latest
+ outputs:
+ matrix: ${{ steps.set-matrix.outputs.matrix }}
+ steps:
+ - uses: actions/checkout@v4
+ - name: Generate matrix
+ id: set-matrix
+ run: |
+ matrix=$(ruby script/gh/docker-tags.rb --matrix)
+ echo "matrix=$matrix" >> $GITHUB_OUTPUT
+
+ build:
+ needs: generate-matrix
+ strategy:
+ matrix: ${{ fromJson(needs.generate-matrix.outputs.matrix) }}
+ uses: ./.github/workflows/docker.yml
+ with:
+ branch: ${{ matrix.branch }}
+ tag: ${{ matrix.tag }}
+ secrets: inherit
\ No newline at end of file
diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml
index 402aa15a9b9..f17a06ee6f7 100644
--- a/.github/workflows/docker.yml
+++ b/.github/workflows/docker.yml
@@ -1,65 +1,38 @@
name: Docker
+run-name: Build docker image from branch ${{ inputs.branch }} with tag ${{ inputs.tag }}
on:
- # build dev daily
- schedule:
- - cron: "20 2 * * *" # Daily at 02:20
-
- push:
- tags:
- - v*
- workflow_dispatch:
+ workflow_call:
inputs:
+ branch:
+ description: "The branch or tag to checkout and build"
+ required: true
+ type: string
tag:
- description: "The tag to release. Note that this happens by default on the tag push. Only run this action when something went wrong!"
- required: false
+ description: "The main docker tag to use (e.g., 'dev' or '16.3.0')"
+ required: true
+ type: string
permissions:
contents: read # to fetch code (actions/checkout)
env:
- REGISTRY_IMAGE: openproject/openproject
+ # FIXME: change back to openproject/openproject once workflows are confirmed to be doing the right thing
+ REGISTRY_IMAGE: openproject/openproject-test
jobs:
setup:
runs-on: ubuntu-latest
steps:
- - name: Extract version
- id: extract_version
- run: |
- if [[ ${{ github.event_name }} == 'push' ]]; then
- TAG_REF=${GITHUB_REF#refs/tags/}
- CHECKOUT_REF=$GITHUB_REF
- elif [[ ${{ github.event_name }} == 'schedule' ]]; then
- TAG_REF=dev
- CHECKOUT_REF=refs/heads/dev
- elif [[ ${{ github.event_name }} == 'workflow_dispatch' ]]; then
- TAG_REF=${{ inputs.tag }}
- CHECKOUT_REF=${{ inputs.tag }}
-
- if [ -z "$TAG_REF" ]; then
- TAG_REF=dev
- CHECKOUT_REF=dev
- fi
- else
- echo "Unsupported event"
- exit 1
- fi
-
- if [ -z "$TAG_REF" ] || [ -z "$CHECKOUT_REF" ]; then
- echo "No TAG_REF or CHECKOUT_REF set. Aborting"
- exit 1
- fi
-
- VERSION=${TAG_REF#v}
- echo "Version: $VERSION"
- echo "Checkout REF: $CHECKOUT_REF"
- echo "version=$VERSION" >> "$GITHUB_OUTPUT"
- echo "checkout_ref=$CHECKOUT_REF" >> "$GITHUB_OUTPUT"
- name: Checkout
uses: actions/checkout@v5
with:
- ref: ${{ steps.extract_version.outputs.checkout_ref }}
+ ref: ${{ inputs.branch }}
+ - name: Set version outputs and convert tags
+ id: extract_version
+ run: |
+ echo "version=$(./script/gh/docker-tags.rb "${{ inputs.tag }}" --version)" >> "$GITHUB_OUTPUT"
+ echo "docker_tags=$(./script/gh/docker-tags.rb "${{ inputs.tag }}" --format-for-docker)" >> "$GITHUB_OUTPUT"
- name: Cache NPM
uses: runs-on/cache@v4
with:
@@ -99,17 +72,13 @@ jobs:
include-hidden-files: true
outputs:
version: ${{ steps.extract_version.outputs.version }}
- checkout_ref: ${{ steps.extract_version.outputs.checkout_ref }}
+ docker_tags: ${{ steps.extract_version.outputs.docker_tags }}
build:
+ if: github.repository == 'opf/openproject'
needs:
- setup
- if: github.repository == 'opf/openproject'
runs-on:
- labels:
- - runs-on
- - ssh=false
- - run-id=${{ github.run_id }}
- - ${{ matrix.runner }}
+ labels: "runs-on=${{ github.run_id }}/ssh=false/${{ matrix.runner }}"
strategy:
matrix:
include:
@@ -137,7 +106,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v5
with:
- ref: ${{ needs.setup.outputs.checkout_ref }}
+ ref: ${{ inputs.branch }}
- name: Prepare docker files
run: |
cp ./docker/prod/Dockerfile ./Dockerfile
@@ -157,8 +126,8 @@ jobs:
echo '!/config/frontend_assets.manifest.json' >> .dockerignore
- name: Add build information
run: |
- echo "${{ needs.setup.outputs.checkout_ref }}" > PRODUCT_VERSION
- echo "https://github.com/opf/openproject/commits/${{ needs.setup.outputs.checkout_ref }}" > PRODUCT_URL
+ echo "${{ inputs.branch }}" > PRODUCT_VERSION
+ echo "https://github.com/opf/openproject/commits/${{ inputs.branch }}" > PRODUCT_URL
date -u +"%Y-%m-%dT%H:%M:%SZ" > RELEASE_DATE
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
@@ -182,7 +151,7 @@ jobs:
org.opencontainers.image.documentation=https://www.openproject.org/docs/installation-and-operations/installation/
org.opencontainers.image.vendor=OpenProject GmbH
tags: |
- type=semver,pattern={{version}},value=${{ needs.setup.outputs.version }}
+ ${{ needs.setup.outputs.docker_tags }}
images: |
${{ env.REGISTRY_IMAGE }}
- name: Restore vendor/bundle
@@ -318,10 +287,7 @@ jobs:
latest=false
suffix=${{ steps.set_suffix.outputs.suffix }}
tags: |
- type=semver,pattern={{version}},value=${{ needs.setup.outputs.version }}
- type=semver,pattern={{major}}.{{minor}},value=${{ needs.setup.outputs.version }}
- type=semver,pattern={{major}},value=${{ needs.setup.outputs.version }}
- type=raw,value=dev,priority=200,enable={{is_default_branch}}
+ ${{ needs.setup.outputs.docker_tags }}
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
@@ -343,20 +309,3 @@ jobs:
with:
subject: "Docker build failed"
body: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
- trigger_helm_release:
- needs: [setup, build, merge]
- permissions:
- contents: none
- if: ${{ github.repository == 'opf/openproject' }}
- runs-on: ubuntu-latest
- steps:
- - name: Trigger Helm charts release
- env:
- TOKEN: ${{ secrets.OPENPROJECT_CI_TOKEN }}
- REPOSITORY: opf/helm-charts
- WORKFLOW_ID: core_release.yml
- run: |
- curl -i --fail-with-body -H"authorization: Bearer $TOKEN" \
- -XPOST -H"Accept: application/vnd.github.v3+json" \
- https://api.github.com/repos/$REPOSITORY/actions/workflows/$WORKFLOW_ID/dispatches \
- -d '{"ref": "main", "inputs": { "tag" : "${{ needs.setup.outputs.version }}" }}'
diff --git a/script/gh/docker-tags.rb b/script/gh/docker-tags.rb
new file mode 100755
index 00000000000..6eec3aad841
--- /dev/null
+++ b/script/gh/docker-tags.rb
@@ -0,0 +1,132 @@
+#!/usr/bin/env ruby
+# frozen_string_literal: true
+
+require "optparse"
+require "net/http"
+require "json"
+
+def latest_release_major_minor
+ uri = URI("https://api.github.com/repos/opf/openproject/releases/latest")
+ res = Net::HTTP.get_response(uri)
+ if res.is_a?(Net::HTTPSuccess)
+ tag_name = JSON.parse(res.body)["tag_name"]
+ tag_name[/^v?(\d+\.\d+)/, 1]
+ end
+rescue StandardError
+ puts "Error getting latest release major: #{$!}"
+ nil
+end
+
+def generate_matrix
+ latest_version = latest_release_major_minor
+ return nil unless latest_version
+
+ {
+ "include" => [
+ {
+ "branch" => "dev",
+ "tag" => "dev"
+ },
+ {
+ "branch" => "release/#{latest_version}",
+ "tag" => "#{latest_version}-rc"
+ }
+ ]
+ }
+end
+
+class Tag
+ def initialize(tag)
+ @tag = tag
+ end
+
+ def semver?
+ @tag.match?(/^v(\d+\.\d+\.\d+.*)$/)
+ end
+
+ def rc?
+ @tag.match?(/-rc$/)
+ end
+
+ def version
+ @tag.sub(/^v/, "").sub(/-rc$/, "")
+ end
+
+ def to_semver_docker_tags
+ if semver?
+ [
+ "type=semver,pattern={{version}},value=#{version}",
+ "type=semver,pattern={{major}}.{{minor}},value=#{version}",
+ "type=semver,pattern={{major}},value=#{version}"
+ ]
+ elsif rc?
+ latest_major_minor = latest_release_major_minor
+ tags = [
+ "type=raw,value=#{major}.#{minor}-rc",
+ "type=raw,value=#{major}-rc"
+ ]
+ if latest_major_minor && latest_major_minor == [major, minor].join(".")
+ tags << [
+ "type=raw,value=rc"
+ ]
+ end
+ tags
+ else
+ ["type=raw,value=#{version}"]
+ end
+ end
+
+ def major
+ return unless semver? || rc?
+
+ version.split(".")[0]
+ end
+
+ def minor
+ return unless semver? || rc?
+
+ version.split(".")[1]
+ end
+end
+
+def main # rubocop:disable Metrics/AbcSize
+ options = {}
+ OptionParser.new do |opts|
+ opts.banner = "Usage: #{$0} [TAG] [options]"
+ opts.on("--format-for-docker", "Output formatted tags for docker metadata") do
+ options[:format_for_docker] = true
+ end
+ opts.on("--version", "Output first tag as version") do
+ options[:version] = true
+ end
+ opts.on("--matrix", "Generate matrix for GitHub Actions workflow") do
+ options[:matrix] = true
+ end
+ opts.on("-h", "--help", "Prints this help") do
+ puts opts
+ exit
+ end
+ end.parse!
+
+ if options[:matrix]
+ matrix = generate_matrix
+ if matrix
+ puts JSON.pretty_generate(matrix)
+ else
+ puts "Error: Could not generate matrix"
+ exit 1
+ end
+ else
+ tag = Tag.new(ARGV.first)
+ if options[:version]
+ puts tag.version
+ elsif options[:format_for_docker]
+ puts tag.to_semver_docker_tags.join("\n")
+ else
+ puts "Error: Must specify either --version, --format-for-docker, or --matrix"
+ exit 1
+ end
+ end
+end
+
+main if __FILE__ == $0