diff --git a/.github/workflows/service.yml b/.github/workflows/service.yml new file mode 100644 index 0000000000..0bc8bb8008 --- /dev/null +++ b/.github/workflows/service.yml @@ -0,0 +1,47 @@ +# Copyright 2022-Present Couchbase, Inc. +# +# Use of this software is governed by the Business Source License included in +# the file licenses/BSL-Couchbase.txt. As of the Change Date specified in that +# file, in accordance with the Business Source License, use of this software +# will be governed by the Apache License, Version 2.0, included in the file +# licenses/APL2.txt. + +name: service + +on: + push: + # Only run when we modify service files + paths: + - 'service/**' + - 'integration-test/**' + branches: + - 'main' + - 'release/*' + - 'feature/*' + - 'beryllium' + - 'CBG*' + - 'ci-*' + - 'api-ci-*' + pull_request: + # Only run when we modify service files + paths: + - 'service/**' + - 'integration-test/**' + branches: + - 'main' + - 'release/*' + +jobs: + scripts: + runs-on: ubuntu-latest + name: Verify service script installation. + steps: + - uses: actions/checkout@v4 + # build sync gateway since the executable is needed for service installation + - uses: actions/setup-go@v5 + with: + go-version: 1.22.5 + - name: "Build Sync Gateway" + run: mkdir -p ./bin && go build -o ./bin ./... + - name: "Run test scripts" + run: ./integration-test/service-install-tests.sh diff --git a/integration-test/service-install-tests.sh b/integration-test/service-install-tests.sh new file mode 100755 index 0000000000..1440cc373b --- /dev/null +++ b/integration-test/service-install-tests.sh @@ -0,0 +1,42 @@ +#!/bin/bash +# Copyright 2024-Present Couchbase, Inc. +# +# Use of this software is governed by the Business Source License included +# in the file licenses/BSL-Couchbase.txt. As of the Change Date specified +# in that file, in accordance with the Business Source License, use of this +# software will be governed by the Apache License, Version 2.0, included in +# the file licenses/APL2.txt. + +# This file is used by github CI or locally and runs a subset of test scripts to validate the service installation done by the package managers. This is intended to be run from Linux or Mac. + +set -eux -o pipefail + +IMAGES=( + "almalinux:9" + "amazonlinux:2" + "amazonlinux:2023" + "debian:10" + "debian:11" + "debian:12" + "redhat/ubi8" + "redhat/ubi9" + "rockylinux:9" + "ubuntu:20.04" + "ubuntu:22.04" + "ubuntu:24.04" + + # not technically supported + "oraclelinux:9" +) + +SCRIPT_DIR=$(dirname "${BASH_SOURCE[0]}") +SYNC_GATEWAY_DIR=$(realpath ${SCRIPT_DIR}/..) + +if [ "$(uname)" == "Darwin" ]; then + sudo ${SYNC_GATEWAY_DIR}/integration-test/service-test.sh +fi + +for IMAGE in "${IMAGES[@]}"; do + echo "Running tests for ${IMAGE}" + docker run --mount src=${SYNC_GATEWAY_DIR},target=/sync_gateway,type=bind ${IMAGE} /bin/bash -c "/sync_gateway/integration-test/service-test.sh" +done diff --git a/integration-test/service-test.sh b/integration-test/service-test.sh new file mode 100755 index 0000000000..3320595672 --- /dev/null +++ b/integration-test/service-test.sh @@ -0,0 +1,70 @@ +#/bin/sh + +# Copyright 2024-Present Couchbase, Inc. +# +# Use of this software is governed by the Business Source License included +# in the file licenses/BSL-Couchbase.txt. As of the Change Date specified +# in that file, in accordance with the Business Source License, use of this +# software will be governed by the Apache License, Version 2.0, included in +# the file licenses/APL2.txt. + +# This code is intneded to be run from within a docker container of a specific platform and runs a subset of the service scripts. The full service can not be validated since systemd does not work in docker contains. This is intended to run in /bin/sh to test dash environments on debian systems. + +set -eux -o pipefail + +SCRIPT_DIR=$(dirname "${BASH_SOURCE[0]}") + +cd ${SCRIPT_DIR}/../service + +./sync_gateway_service_install.sh --servicecmd + +# /etc/os-release doesn't exist on Darwin +if [ -f /etc/os-release ]; then + . /etc/os-release + case ${ID} in + amzn) + yum install -y shadow-utils systemd + ;; + esac + + groupadd -r sync_gateway + useradd -g sync_gateway sync_gateway + + # bash would support export -f for a systemctl wrapper, but dash does not support exporting aliases or functions + + mkdir -p /tmp/systemctl_wrapper + + cat << 'EOF' > /tmp/systemctl_wrapper/systemctl +#!/bin/bash + +set -eu -o pipefail + +case ${1:-} in +start) + echo "No-op systemctl start in docker, since we're not running systemd" + ;; +stop) + echo "No-op systemctl stop in docker, since we're not running systemd" + ;; +*) + echo "Running systemctl $@" + command /usr/bin/systemctl "$@" + ;; +esac +EOF + + chmod +x /tmp/systemctl_wrapper/systemctl + + export PATH=/tmp/systemctl_wrapper:$PATH +fi + +./sync_gateway_service_install.sh +./sync_gateway_service_upgrade.sh +./sync_gateway_service_uninstall.sh + +# test again with runas option +./sync_gateway_service_install.sh --runas=root +./sync_gateway_service_upgrade.sh +./sync_gateway_service_uninstall.sh + +echo "Successful service test" diff --git a/service/sync_gateway_service_install.sh b/service/sync_gateway_service_install.sh index ba7e305979..68b7858091 100755 --- a/service/sync_gateway_service_install.sh +++ b/service/sync_gateway_service_install.sh @@ -32,7 +32,7 @@ LOGS_TEMPLATE_VAR=${RUNBASE_TEMPLATE_VAR}/logs SERVICE_CMD_ONLY=false usage() { - echo "This script creates an init service to run a sync_gateway instance." + echo "This script creates a service to run a sync_gateway instance." echo "If you want to install more than one service instance" echo "create additional services with different names." echo "" @@ -242,7 +242,7 @@ ubuntu) ;; esac ;; -redhat* | rhel* | centos | ol) +redhat* | rhel* | centos | ol | rocky | almalinux ) case 1:${OS_MAJOR_VERSION:--} in $((OS_MAJOR_VERSION >= 7))*) if [ "$SERVICE_CMD_ONLY" = true ]; then @@ -255,7 +255,7 @@ redhat* | rhel* | centos | ol) fi ;; *) - echo "ERROR: Unsupported RedHat/CentOS Version \"$VER\"" + echo "ERROR: Unsupported RedHat/CentOS/Rocky/Alma Version \"$VER\"" usage exit 1 ;; diff --git a/service/sync_gateway_service_uninstall.sh b/service/sync_gateway_service_uninstall.sh index e5f94002f0..ef518c024c 100755 --- a/service/sync_gateway_service_uninstall.sh +++ b/service/sync_gateway_service_uninstall.sh @@ -32,7 +32,7 @@ LOGS_TEMPLATE_VAR=${RUNBASE_TEMPLATE_VAR}/logs SERVICE_CMD_ONLY=false usage() { - echo "This script removes an init service to run a sync_gateway instance." + echo "This script removes a service to run a sync_gateway instance." } ostype() { @@ -120,7 +120,7 @@ ubuntu) ;; esac ;; -redhat* | rhel* | centos | ol) +redhat* | rhel* | centos | ol | rocky | almalinux ) case 1:${OS_MAJOR_VERSION:--} in $((OS_MAJOR_VERSION >= 7))*) systemctl stop ${SERVICE_NAME} @@ -131,7 +131,7 @@ redhat* | rhel* | centos | ol) fi ;; *) - echo "ERROR: Unsupported RedHat/CentOS Version \"$VER\"" + echo "ERROR: Unsupported RedHat/CentOS/Rocky/Alma Version \"$VER\"" usage exit 1 ;; diff --git a/service/sync_gateway_service_upgrade.sh b/service/sync_gateway_service_upgrade.sh index 815d070589..46f0ce34a0 100755 --- a/service/sync_gateway_service_upgrade.sh +++ b/service/sync_gateway_service_upgrade.sh @@ -32,7 +32,7 @@ LOGS_TEMPLATE_VAR=${RUNBASE_TEMPLATE_VAR}/logs SERVICE_CMD_ONLY=false usage() { - echo "This script upgrades an init service to run a sync_gateway instance." + echo "This script upgrades a service to run a sync_gateway instance." } ostype() { @@ -110,14 +110,14 @@ ubuntu) ;; esac ;; -redhat* | rhel* | centos | ol) +redhat* | rhel* | centos | ol | rocky | almalinux ) case 1:${OS_MAJOR_VERSION:--} in $((OS_MAJOR_VERSION >= 7))*) systemctl stop ${SERVICE_NAME} systemctl start ${SERVICE_NAME} ;; *) - echo "ERROR: Unsupported RedHat/CentOS Version \"$VER\"" + echo "ERROR: Unsupported RedHat/CentOS/Rocky/Alma Version \"$VER\"" usage exit 1 ;;