Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
5 changes: 5 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,8 @@ insert_final_newline = false
[*.yml,*.yaml]
indent_style = space
indent_size = 2

[*.mdx]
indent_style = space
indent_size = 2
trim_trailing_whitespace = false
66 changes: 66 additions & 0 deletions .github/actions/load-buildenv/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Load build environment
description: >
Loads build-server images uploaded by setup-buildenv into the local Docker
daemon, and resolves the image name from the Go version. Use in jobs that
run the container directly (test jobs). For jobs that only need a shell
inside the container, use run-in-buildenv instead.

inputs:
go-version:
description: "Go version used to construct the image tag (e.g. 1.26.3)."
required: true
fips-enabled:
description: "Set to 'true' to resolve the FIPS build image"
required: false
default: "false"

outputs:
image:
description: "Fully-qualified build image name (e.g. mattermost/mattermost-build-server:1.26.3)."
value: ${{ steps.resolve.outputs.image }}

runs:
using: composite
steps:
- name: Set constants
shell: bash
run: |
echo "BUILDENV_ARTIFACT=buildenv-image" >> "${GITHUB_ENV}"
echo "BUILDENV_FIPS_ARTIFACT=buildenv-fips-image" >> "${GITHUB_ENV}"
echo "BUILDENV_TMPDIR=/tmp/buildenv-save" >> "${GITHUB_ENV}"
- name: Download buildenv artifact
id: download
if: ${{ inputs.fips-enabled != 'true' }}
continue-on-error: true
uses: actions/download-artifact@70fc10c6e5e1ce46ad2ea6f2b72d43f7d47b13c3 # v8.0.0
with:
name: ${{ env.BUILDENV_ARTIFACT }}
path: ${{ env.BUILDENV_TMPDIR }}/
- name: Load buildenv from artifact
if: ${{ inputs.fips-enabled != 'true' && steps.download.outcome == 'success' }}
shell: bash
run: docker load -i "${BUILDENV_TMPDIR}/image.tar.gz"
- name: Download buildenv-fips artifact
id: download-fips
if: ${{ inputs.fips-enabled == 'true' }}
continue-on-error: true
uses: actions/download-artifact@70fc10c6e5e1ce46ad2ea6f2b72d43f7d47b13c3 # v8.0.0
with:
name: ${{ env.BUILDENV_FIPS_ARTIFACT }}
path: ${{ env.BUILDENV_TMPDIR }}/
- name: Load buildenv-fips from artifact
if: ${{ inputs.fips-enabled == 'true' && steps.download-fips.outcome == 'success' }}
shell: bash
run: docker load -i "${BUILDENV_TMPDIR}/image-fips.tar.gz"
- name: Resolve image name
id: resolve
shell: bash
env:
FIPS: ${{ inputs.fips-enabled }}
GO_VERSION: ${{ inputs.go-version }}
run: |
if [[ "${FIPS}" == 'true' ]]; then
echo "image=mattermost/mattermost-build-server-fips:${GO_VERSION}" >> "${GITHUB_OUTPUT}"
else
echo "image=mattermost/mattermost-build-server:${GO_VERSION}" >> "${GITHUB_OUTPUT}"
fi
69 changes: 69 additions & 0 deletions .github/actions/run-in-buildenv/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: Run in build environment
description: >
Runs a script inside the build-server container. Use for build and check
jobs that don't need direct control over the docker run invocation.

Note the special handling of HEAD_REF, REF_NAME, and RUN_ID. Since the
container is not otherwise given access to the runner's environment, we
re-export github.head_ref, github.ref_name, and github.run_id as a
special case for use in safely building up BUILD_NUMBER. In general,
don't extend this: if your use case requires more customization, use
load-buildenv and invoke docker run yourself.

inputs:
run:
description: "Bash script to execute inside the container"
required: true
go-version:
description: "Go version to use (e.g. 1.24.3). Defaults to the version in server/.go-version."
required: false
default: ""
fips-enabled:
description: "Set to 'true' to use the FIPS build image"
required: false
default: "false"
working-directory:
description: "Working directory inside the container (absolute path under /mattermost/)"
required: false
default: "/mattermost/server"

runs:
using: composite
steps:
- name: Read Go version
shell: bash
env:
GO_VERSION_INPUT: ${{ inputs.go-version }}
run: |
if [[ -n "${GO_VERSION_INPUT}" ]]; then
echo "GO_VERSION=${GO_VERSION_INPUT}" >> "${GITHUB_ENV}"
else
echo "GO_VERSION=$(cat server/.go-version)" >> "${GITHUB_ENV}"
fi
- uses: ./.github/actions/load-buildenv
id: buildenv
with:
go-version: ${{ env.GO_VERSION }}
fips-enabled: ${{ inputs.fips-enabled }}
- name: Run in buildenv
shell: bash
env:
CMD: ${{ inputs.run }}
IMAGE: ${{ steps.buildenv.outputs.image }}
WORKING_DIR: ${{ inputs.working-directory }}
HEAD_REF: ${{ github.head_ref }}
REF_NAME: ${{ github.ref_name }}
RUN_ID: ${{ github.run_id }}
run: |
SCRIPT=$(mktemp)
printf 'git config --global --add safe.directory /mattermost\n' > "${SCRIPT}"
printf '%s\n' "${CMD}" >> "${SCRIPT}"
docker run --rm \
--network host \
-e HEAD_REF -e REF_NAME -e RUN_ID \
-v "$PWD:/mattermost" \
-v "${SCRIPT}:/run-script.sh" \
-w "${WORKING_DIR}" \
"${IMAGE}" \
bash -eo pipefail /run-script.sh
rm -f "${SCRIPT}"
104 changes: 104 additions & 0 deletions .github/actions/setup-buildenv/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
name: Setup build environment
description: >
Builds the mattermost-build-server images if they don't yet exist on Docker
Hub (e.g. during a Go version bump), and uploads them as artifacts for
downstream jobs. Run once per workflow before any build or test jobs.

inputs:
go-version:
description: "Go version (e.g. 1.26.3)"
required: true
dockerfile:
description: "Path to Dockerfile.buildenv (relative to workspace root)"
required: false
default: "server/build/Dockerfile.buildenv"
dockerfile-fips:
description: "Path to Dockerfile.buildenv-fips (relative to workspace root)"
required: false
default: "server/build/Dockerfile.buildenv-fips"

runs:
using: composite
steps:
- name: Set constants
shell: bash
run: |
echo "BUILDENV_IMAGE=mattermost/mattermost-build-server" >> "${GITHUB_ENV}"
echo "BUILDENV_ARTIFACT=buildenv-image" >> "${GITHUB_ENV}"
echo "BUILDENV_DOCKERFILE=${{ inputs.dockerfile }}" >> "${GITHUB_ENV}"
echo "BUILDENV_FIPS_IMAGE=mattermost/mattermost-build-server-fips" >> "${GITHUB_ENV}"
echo "BUILDENV_FIPS_ARTIFACT=buildenv-fips-image" >> "${GITHUB_ENV}"
echo "BUILDENV_FIPS_DOCKERFILE=${{ inputs.dockerfile-fips }}" >> "${GITHUB_ENV}"
echo "BUILDENV_TMPDIR=/tmp/buildenv-save" >> "${GITHUB_ENV}"
# ── Regular ────────────────────────────────────────────────────────
- name: Resolve regular image
id: resolve
shell: bash
env:
GO_VERSION: ${{ inputs.go-version }}
run: |
docker manifest inspect "${BUILDENV_IMAGE}:${GO_VERSION}" > /dev/null 2>&1 || \
echo "needs-build=true" >> "${GITHUB_OUTPUT}"
- name: Build regular image
if: ${{ steps.resolve.outputs.needs-build == 'true' }}
shell: bash
env:
GO_VERSION: ${{ inputs.go-version }}
run: docker build -t "${BUILDENV_IMAGE}:${GO_VERSION}" - < "${BUILDENV_DOCKERFILE}"
- name: Save and upload regular image
if: ${{ steps.resolve.outputs.needs-build == 'true' }}
shell: bash
env:
GO_VERSION: ${{ inputs.go-version }}
run: |
mkdir -p "${BUILDENV_TMPDIR}"
docker save "${BUILDENV_IMAGE}:${GO_VERSION}" | gzip > "${BUILDENV_TMPDIR}/image.tar.gz"
- name: Upload regular image artifact
if: ${{ steps.resolve.outputs.needs-build == 'true' }}
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
with:
name: ${{ env.BUILDENV_ARTIFACT }}
path: ${{ env.BUILDENV_TMPDIR }}/image.tar.gz
retention-days: 1
# ── FIPS (skipped on fork PRs) ─────────────────────────────────────
- name: Docker Hub login
if: ${{ github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository }}
uses: docker/login-action@b45d80f862d83dbcd57f89517bcf500b2ab88fb2 # v4.0.0
with:
username: ${{ env.DOCKERHUB_USERNAME }}
password: ${{ env.DOCKERHUB_TOKEN }}
- name: Setup Chainctl
if: ${{ github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository }}
uses: chainguard-dev/setup-chainctl@c125f765e82b09a42af3185f3214465314d75c5d # v0.5.0
with:
identity: ${{ env.CHAINCTL_IDENTITY }}
- name: Resolve FIPS image
id: resolve-fips
if: ${{ github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository }}
shell: bash
env:
GO_VERSION: ${{ inputs.go-version }}
run: |
docker manifest inspect "${BUILDENV_FIPS_IMAGE}:${GO_VERSION}" > /dev/null 2>&1 || \
echo "needs-build=true" >> "${GITHUB_OUTPUT}"
- name: Build FIPS image
if: ${{ steps.resolve-fips.outputs.needs-build == 'true' }}
shell: bash
env:
GO_VERSION: ${{ inputs.go-version }}
run: docker build -t "${BUILDENV_FIPS_IMAGE}:${GO_VERSION}" - < "${BUILDENV_FIPS_DOCKERFILE}"
- name: Save and upload FIPS image
if: ${{ steps.resolve-fips.outputs.needs-build == 'true' }}
shell: bash
env:
GO_VERSION: ${{ inputs.go-version }}
run: |
mkdir -p "${BUILDENV_TMPDIR}"
docker save "${BUILDENV_FIPS_IMAGE}:${GO_VERSION}" | gzip > "${BUILDENV_TMPDIR}/image-fips.tar.gz"
- name: Upload FIPS image artifact
if: ${{ steps.resolve-fips.outputs.needs-build == 'true' }}
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
with:
name: ${{ env.BUILDENV_FIPS_ARTIFACT }}
path: ${{ env.BUILDENV_TMPDIR }}/image-fips.tar.gz
retention-days: 1
19 changes: 11 additions & 8 deletions .github/workflows/mmctl-test-template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,22 @@ jobs:
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Checkout mattermost project
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- name: Setup BUILD_IMAGE
id: build
- name: buildenv/load
id: buildenv
uses: ./.github/actions/load-buildenv
with:
go-version: ${{ inputs.go-version }}
fips-enabled: ${{ inputs.fips-enabled }}
- name: Setup log artifact name
id: log-artifact
run: |
if [[ "$INPUT_FIPS_ENABLED" == 'true' ]]; then
echo "BUILD_IMAGE=mattermost/mattermost-build-server-fips:${INPUT_GO_VERSION}" >> "${GITHUB_OUTPUT}"
echo "LOG_ARTIFACT_NAME=${INPUT_LOGSARTIFACT}-fips" >> "${GITHUB_OUTPUT}"
else
echo "BUILD_IMAGE=mattermost/mattermost-build-server:${INPUT_GO_VERSION}" >> "${GITHUB_OUTPUT}"
echo "LOG_ARTIFACT_NAME=${INPUT_LOGSARTIFACT}" >> "${GITHUB_OUTPUT}"
fi

Expand All @@ -90,7 +93,7 @@ jobs:

- name: Run mmctl Tests
env:
BUILD_IMAGE: ${{ steps.build.outputs.BUILD_IMAGE }}
BUILD_IMAGE: ${{ steps.buildenv.outputs.image }}
run: |
if [[ "$REF_NAME" == 'master' ]]; then
export TESTFLAGS="-timeout 90m -race"
Expand Down Expand Up @@ -120,13 +123,13 @@ jobs:
with:
report-path: server/report.xml
zephyr-api-key: ${{ secrets.MM_E2E_ZEPHYR_API_KEY }}
build-image: ${{ steps.build.outputs.BUILD_IMAGE }}
build-image: ${{ steps.buildenv.outputs.image }}

- name: Archive logs
if: ${{ always() }}
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
with:
name: ${{ steps.build.outputs.LOG_ARTIFACT_NAME }}
name: ${{ steps.log-artifact.outputs.LOG_ARTIFACT_NAME }}
path: |
server/gotestsum.json
server/report.xml
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/server-ci-nightly-race.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ permissions:
contents: read

jobs:
go:
name: Compute Go Version
buildenv:
name: Build Environment
runs-on: ubuntu-22.04
outputs:
version: ${{ steps.calculate.outputs.GO_VERSION }}
Expand All @@ -38,7 +38,7 @@ jobs:

test-race:
name: Race Detector
needs: go
needs: buildenv
permissions:
contents: read
actions: write
Expand All @@ -48,7 +48,7 @@ jobs:
datasource: postgres://mmuser:mostest@postgres:5432/mattermost_test?sslmode=disable&connect_timeout=10
drivername: postgres
logsartifact: race-detector-server-test-logs
go-version: ${{ needs.go.outputs.version }}
go-version: ${{ needs.buildenv.outputs.version }}
fips-enabled: false
fullyparallel: false
race-enabled: true
Expand Down
Loading
Loading