ci: make CI a little faster and less flaky

- use latest ubuntu22.04 emqx-builder image in compose files
- use xl runners for compiling and for emqx app tests
- make helm tests less flaky
This commit is contained in:
Ivan Dyachkov 2023-10-30 10:32:27 +01:00
parent 45fdf8da1b
commit 045875d18d
8 changed files with 109 additions and 79 deletions

View File

@ -18,7 +18,7 @@ services:
- /tmp/emqx-ci/emqx-shared-secret:/var/lib/secret - /tmp/emqx-ci/emqx-shared-secret:/var/lib/secret
kdc: kdc:
hostname: kdc.emqx.net hostname: kdc.emqx.net
image: ghcr.io/emqx/emqx-builder/5.1-4:1.14.5-25.3.2-2-ubuntu20.04 image: ghcr.io/emqx/emqx-builder/5.2-3:1.14.5-25.3.2-2-ubuntu22.04
container_name: kdc.emqx.net container_name: kdc.emqx.net
expose: expose:
- 88 # kdc - 88 # kdc

View File

@ -3,17 +3,17 @@ version: '3.9'
services: services:
erlang: erlang:
container_name: erlang container_name: erlang
image: ${DOCKER_CT_RUNNER_IMAGE:-ghcr.io/emqx/emqx-builder/5.1-4:1.14.5-25.3.2-2-ubuntu20.04} image: ${DOCKER_CT_RUNNER_IMAGE:-ghcr.io/emqx/emqx-builder/5.2-3:1.14.5-25.3.2-2-ubuntu22.04}
env_file: env_file:
- conf.env - conf.env
environment: environment:
GITHUB_ACTIONS: ${GITHUB_ACTIONS} GITHUB_ACTIONS: ${GITHUB_ACTIONS:-}
GITHUB_TOKEN: ${GITHUB_TOKEN} GITHUB_TOKEN: ${GITHUB_TOKEN:-}
GITHUB_RUN_ID: ${GITHUB_RUN_ID} GITHUB_RUN_ID: ${GITHUB_RUN_ID:-}
GITHUB_SHA: ${GITHUB_SHA} GITHUB_SHA: ${GITHUB_SHA:-}
GITHUB_RUN_NUMBER: ${GITHUB_RUN_NUMBER} GITHUB_RUN_NUMBER: ${GITHUB_RUN_NUMBER:-}
GITHUB_EVENT_NAME: ${GITHUB_EVENT_NAME} GITHUB_EVENT_NAME: ${GITHUB_EVENT_NAME:-}
GITHUB_REF: ${GITHUB_REF} GITHUB_REF: ${GITHUB_REF:-}
networks: networks:
- emqx_bridge - emqx_bridge
ports: ports:

View File

@ -25,6 +25,7 @@ jobs:
version-emqx: ${{ steps.matrix.outputs.version-emqx }} version-emqx: ${{ steps.matrix.outputs.version-emqx }}
version-emqx-enterprise: ${{ steps.matrix.outputs.version-emqx-enterprise }} version-emqx-enterprise: ${{ steps.matrix.outputs.version-emqx-enterprise }}
runner_labels: ${{ github.repository_owner == 'emqx' && '["self-hosted","ephemeral","linux","x64"]' || '["ubuntu-22.04"]' }} runner_labels: ${{ github.repository_owner == 'emqx' && '["self-hosted","ephemeral","linux","x64"]' || '["ubuntu-22.04"]' }}
xl_runner_labels: ${{ github.repository_owner == 'emqx' && '["self-hosted","ephemeral-xl","linux","x64"]' || '["ubuntu-22.04"]' }}
builder: "ghcr.io/emqx/emqx-builder/5.2-3:1.14.5-25.3.2-2-ubuntu22.04" builder: "ghcr.io/emqx/emqx-builder/5.2-3:1.14.5-25.3.2-2-ubuntu22.04"
builder_vsn: "5.2-3" builder_vsn: "5.2-3"
otp_vsn: "25.3.2-2" otp_vsn: "25.3.2-2"
@ -115,7 +116,7 @@ jobs:
echo "version-emqx-enterprise=$(./pkg-vsn.sh emqx-enterprise)" | tee -a $GITHUB_OUTPUT echo "version-emqx-enterprise=$(./pkg-vsn.sh emqx-enterprise)" | tee -a $GITHUB_OUTPUT
compile: compile:
runs-on: ${{ fromJSON(needs.sanity-checks.outputs.runner_labels) }} runs-on: ${{ fromJSON(needs.sanity-checks.outputs.xl_runner_labels) }}
container: ${{ needs.sanity-checks.outputs.builder }} container: ${{ needs.sanity-checks.outputs.builder }}
needs: needs:
- sanity-checks - sanity-checks
@ -153,7 +154,7 @@ jobs:
- compile - compile
uses: ./.github/workflows/run_emqx_app_tests.yaml uses: ./.github/workflows/run_emqx_app_tests.yaml
with: with:
runner_labels: ${{ needs.sanity-checks.outputs.runner_labels }} runner_labels: ${{ needs.sanity-checks.outputs.xl_runner_labels }}
builder: ${{ needs.sanity-checks.outputs.builder }} builder: ${{ needs.sanity-checks.outputs.builder }}
before_ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.sha || github.event.before }} before_ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.sha || github.event.before }}
after_ref: ${{ github.sha }} after_ref: ${{ github.sha }}

View File

@ -140,12 +140,13 @@ jobs:
echo "waiting emqx started"; echo "waiting emqx started";
sleep 10; sleep 10;
done done
- name: Get Token - name: Setup 18083 port forwarding
run: |
nohup kubectl port-forward service/${EMQX_NAME} 18083:18083 > /dev/null &
- name: Get auth token
run: | run: |
kubectl port-forward service/${EMQX_NAME} 18083:18083 > /dev/null &
curl --head -X GET --retry 10 --retry-connrefused --retry-delay 6 http://localhost:18083/status curl --head -X GET --retry 10 --retry-connrefused --retry-delay 6 http://localhost:18083/status
echo "TOKEN=$(curl --silent -X 'POST' 'http://127.0.0.1:18083/api/v5/login' -H 'accept: application/json' -H 'Content-Type: application/json' -d '{"username": "admin","password": "public"}' | jq -r ".token")" >> $GITHUB_ENV echo "TOKEN=$(curl --silent -X 'POST' 'http://127.0.0.1:18083/api/v5/login' -H 'accept: application/json' -H 'Content-Type: application/json' -d '{"username": "admin","password": "public"}' | jq -r ".token")" >> $GITHUB_ENV
- name: Check cluster - name: Check cluster
timeout-minutes: 1 timeout-minutes: 1
run: | run: |

View File

@ -71,7 +71,7 @@ jobs:
ct_docker: ct_docker:
runs-on: ${{ fromJSON(inputs.runner_labels) }} runs-on: ${{ fromJSON(inputs.runner_labels) }}
name: "ct_docker (${{ matrix.app }}-${{ matrix.suitegroup }})" name: "${{ matrix.app }}-${{ matrix.suitegroup }} (${{ matrix.profile }})"
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
@ -122,7 +122,7 @@ jobs:
ct: ct:
runs-on: ${{ fromJSON(inputs.runner_labels) }} runs-on: ${{ fromJSON(inputs.runner_labels) }}
name: "ct (${{ matrix.app }}-${{ matrix.suitegroup }})" name: "${{ matrix.app }}-${{ matrix.suitegroup }} (${{ matrix.profile }})"
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:

View File

@ -104,6 +104,11 @@ ifneq ($(CASES),)
CASES_ARG := --case $(CASES) CASES_ARG := --case $(CASES)
endif endif
# Allow user-set GROUPS environment variable
ifneq ($(GROUPS),)
GROUPS_ARG := --groups $(GROUPS)
endif
## example: ## example:
## env SUITES=apps/appname/test/test_SUITE.erl CASES=t_foo make apps/appname-ct ## env SUITES=apps/appname/test/test_SUITE.erl CASES=t_foo make apps/appname-ct
define gen-app-ct-target define gen-app-ct-target
@ -115,6 +120,7 @@ ifneq ($(SUITES),)
--name $(CT_NODE_NAME) \ --name $(CT_NODE_NAME) \
--cover_export_name $(CT_COVER_EXPORT_PREFIX)-$(subst /,-,$1) \ --cover_export_name $(CT_COVER_EXPORT_PREFIX)-$(subst /,-,$1) \
--suite $(SUITES) \ --suite $(SUITES) \
$(GROUPS_ARG) \
$(CASES_ARG) $(CASES_ARG)
else else
@echo 'No suites found for $1' @echo 'No suites found for $1'

View File

@ -109,7 +109,21 @@ fi
ERLANG_CONTAINER='erlang' ERLANG_CONTAINER='erlang'
DOCKER_CT_ENVS_FILE="${WHICH_APP}/docker-ct" DOCKER_CT_ENVS_FILE="${WHICH_APP}/docker-ct"
if [ -z "${PROFILE+x}" ]; then
case "${WHICH_APP}" in case "${WHICH_APP}" in
apps/emqx)
export PROFILE='emqx-enterprise'
;;
apps/emqx_bridge)
export PROFILE='emqx-enterprise'
;;
# emqx_connector test suite is using kafka bridge which is only available in emqx-enterprise
apps/emqx_connector)
export PROFILE='emqx-enterprise'
;;
apps/emqx_dashboard)
export PROFILE='emqx-enterprise'
;;
lib-ee*) lib-ee*)
## ensure enterprise profile when testing lib-ee applications ## ensure enterprise profile when testing lib-ee applications
export PROFILE='emqx-enterprise' export PROFILE='emqx-enterprise'
@ -125,6 +139,7 @@ case "${WHICH_APP}" in
export PROFILE="${PROFILE:-emqx}" export PROFILE="${PROFILE:-emqx}"
;; ;;
esac esac
fi
if [ -f "$DOCKER_CT_ENVS_FILE" ]; then if [ -f "$DOCKER_CT_ENVS_FILE" ]; then
# shellcheck disable=SC2002 # shellcheck disable=SC2002
@ -276,14 +291,18 @@ if [ "$STOP" = 'no' ]; then
set -e set -e
fi fi
# rebar, mix and hex cache directory need to be writable by $DOCKER_USER if [ "$DOCKER_USER" != "root" ]; then
docker exec -i $TTY -u root:root "$ERLANG_CONTAINER" bash -c "mkdir -p /.cache /.hex /.mix && chown $DOCKER_USER /.cache /.hex /.mix"
# need to initialize .erlang.cookie manually here because / is not writable by $DOCKER_USER
docker exec -i $TTY -u root:root "$ERLANG_CONTAINER" bash -c "openssl rand -base64 -hex 16 > /.erlang.cookie && chown $DOCKER_USER /.erlang.cookie && chmod 0400 /.erlang.cookie"
# the user must exist inside the container for `whoami` to work # the user must exist inside the container for `whoami` to work
docker exec -i $TTY -u root:root "$ERLANG_CONTAINER" bash -c "useradd --uid $DOCKER_USER -M -d / emqx" || true docker exec -i $TTY -u root:root "$ERLANG_CONTAINER" bash -c \
docker exec -i $TTY -u root:root "$ERLANG_CONTAINER" bash -c "chown -R $DOCKER_USER /var/lib/secret" || true "useradd --uid $DOCKER_USER -M -d / emqx && \
docker exec -i $TTY -u root:root "$ERLANG_CONTAINER" bash -c "$INSTALL_ODBC" || true mkdir -p /.cache /.hex /.mix && \
chown $DOCKER_USER /.cache /.hex /.mix && \
openssl rand -base64 -hex 16 > /.erlang.cookie && \
chown $DOCKER_USER /.erlang.cookie && \
chmod 0400 /.erlang.cookie && \
chown -R $DOCKER_USER /var/lib/secret && \
$INSTALL_ODBC" || true
fi
if [ "$ONLY_UP" = 'yes' ]; then if [ "$ONLY_UP" = 'yes' ]; then
exit 0 exit 0

View File

@ -54,7 +54,7 @@ fi
###### now deal with the github action's matrix. ###### now deal with the github action's matrix.
################################################## ##################################################
format_app_description() { format_app_entry() {
local groups="$2" local groups="$2"
local group=0 local group=0
while [ "$groups" -gt $group ]; do while [ "$groups" -gt $group ]; do
@ -72,48 +72,51 @@ END
done done
} }
describe_app() { matrix() {
app="$1" local runner
local runner="host"
local profile local profile
local entries=()
for app in ${APPS_ALL}; do
if [ -f "${app}/docker-ct" ]; then if [ -f "${app}/docker-ct" ]; then
runner="docker" runner="docker"
else
runner="host"
fi fi
case "${app}" in case "${app}" in
apps/emqx)
entries+=("$(format_app_entry "$app" 5 emqx "$runner")")
entries+=("$(format_app_entry "$app" 5 emqx-enterprise "$runner")")
;;
apps/emqx_bridge)
entries+=("$(format_app_entry "$app" 1 emqx "$runner")")
entries+=("$(format_app_entry "$app" 1 emqx-enterprise "$runner")")
;;
apps/emqx_connector)
entries+=("$(format_app_entry "$app" 1 emqx "$runner")")
entries+=("$(format_app_entry "$app" 1 emqx-enterprise "$runner")")
;;
apps/emqx_dashboard)
entries+=("$(format_app_entry "$app" 1 emqx "$runner")")
entries+=("$(format_app_entry "$app" 1 emqx-enterprise "$runner")")
;;
apps/*) apps/*)
if [[ -f "${app}/BSL.txt" ]]; then if [[ -f "${app}/BSL.txt" ]]; then
profile='emqx-enterprise' profile='emqx-enterprise'
else else
profile='emqx' profile='emqx'
fi fi
entries+=("$(format_app_entry "$app" 1 "$profile" "$runner")")
;; ;;
lib-ee/*) lib-ee/*)
profile='emqx-enterprise' entries+=("$(format_app_entry "$app" 1 emqx-enterprise "$runner")")
;; ;;
*) *)
echo "unknown app: $app" echo "unknown app: $app"
exit 1 exit 1
;; ;;
esac esac
if [[ "$app" == "apps/emqx" ]]; then
suitegroups=5
else
suitegroups=1
fi
format_app_description "$app" "$suitegroups" "$profile" "$runner"
}
matrix() {
local sep='['
for app in ${APPS_ALL}; do
row="$(describe_app "$app")"
if [ -z "$row" ]; then
continue
fi
echo -n "${sep}${row}"
sep=', '
done done
echo ']' echo -n "[$(IFS=,; echo "${entries[*]}")]"
} }
matrix matrix