From d2ffa22204cdb0d81cb9900b60f9b3bdd0f5d2b6 Mon Sep 17 00:00:00 2001 From: Gabriel Adrian Samfira Date: Wed, 2 Aug 2023 17:14:27 +0300 Subject: [PATCH 1/3] Set up ngrok and use sudo Signed-off-by: Gabriel Adrian Samfira --- .github/workflows/integration-tests.yml | 25 ++++++++++++++++++----- test/integration/scripts/setup-garm.sh | 27 ++++++++++--------------- 2 files changed, 31 insertions(+), 21 deletions(-) diff --git a/.github/workflows/integration-tests.yml b/.github/workflows/integration-tests.yml index b52389f1..d0209a5c 100644 --- a/.github/workflows/integration-tests.yml +++ b/.github/workflows/integration-tests.yml @@ -26,23 +26,38 @@ jobs: run: make build - name: Setup GARM - run: sudo --preserve-env ./test/integration/scripts/setup-garm.sh + run: ./test/integration/scripts/setup-garm.sh env: GH_OAUTH_TOKEN: ${{ secrets.GH_OAUTH_TOKEN }} CREDENTIALS_NAME: test-garm-creds + - name: Generate secrets + run: | + function randomStringGenerator() { + tr -dc "a-zA-Z0-9@#$%^&*()_+?><~\`;'" > $GITHUB_ENV + echo "REPO_WEBHOOK_SECRET=$(randomStringGenerator)" >> $GITHUB_ENV + echo "ORG_WEBHOOK_SECRET=$(randomStringGenerator)" >> $GITHUB_ENV + + - name: Set up ngrok + id: ngrok + uses: gabriel-samfira/ngrok-tunnel-action@v1.0 + with: + ngrok_authtoken: ${{ secrets.NGROK_AUTH_TOKEN }} + port: 9997 + tunnel_type: http + + - name: Run integration tests run: go run ./test/integration/e2e.go env: - GARM_BASE_URL: http://127.0.0.1:9997 + GARM_BASE_URL: ${{ steps.ngrok.outputs.tunnel-url }} GARM_USERNAME: admin - GARM_PASSWORD: ${{ secrets.GARM_ADMIN_PASSWORD }} GARM_FULLNAME: Local GARM Admin GARM_EMAIL: admin@example.com GARM_NAME: local_garm CREDENTIALS_NAME: test-garm-creds - REPO_WEBHOOK_SECRET: ${{ secrets.REPO_WEBHOOK_SECRET }} - ORG_WEBHOOK_SECRET: ${{ secrets.ORG_WEBHOOK_SECRET }} - name: Show GARM logs if: always() diff --git a/test/integration/scripts/setup-garm.sh b/test/integration/scripts/setup-garm.sh index b4a86aa4..0811ae0f 100755 --- a/test/integration/scripts/setup-garm.sh +++ b/test/integration/scripts/setup-garm.sh @@ -1,15 +1,10 @@ #!/usr/bin/env bash set -o errexit -if [[ $EUID -ne 0 ]]; then - echo "ERROR: Please run $0 script as root" - exit 1 -fi - DIR="$(dirname $0)" -BINARIES_DIR="$DIR/../../../bin" -CONTRIB_DIR="$DIR/../../../contrib" -CONFIG_DIR="$DIR/../config" +BINARIES_DIR="$PWD/bin" +CONTRIB_DIR="$PWD/contrib" +CONFIG_DIR="$PWD/config" if [[ ! -f $BINARIES_DIR/garm ]] || [[ ! -f $BINARIES_DIR/garm-cli ]]; then echo "ERROR: Please build GARM binaries first" @@ -47,17 +42,17 @@ export JWT_AUTH_SECRET="$(generate_secret)" export DB_PASSPHRASE="$(generate_secret)" # Group "adm" is the LXD daemon group as set by the "canonical/setup-lxd" GitHub action. -useradd --shell /usr/bin/false --system --groups adm --no-create-home garm +sudo useradd --shell /usr/bin/false --system --groups adm --no-create-home garm -mkdir -p /etc/garm -cat $CONFIG_DIR/config.toml | envsubst > /etc/garm/config.toml -chown -R garm:garm /etc/garm +sudo mkdir -p /etc/garm +cat $CONFIG_DIR/config.toml | envsubst | sudo tee /etc/garm/config.toml +sudo chown -R garm:garm /etc/garm -mv $BINARIES_DIR/* /usr/local/bin/ -cp $CONTRIB_DIR/garm.service /etc/systemd/system/garm.service +sudo mv $BINARIES_DIR/* /usr/local/bin/ +sudo cp $CONTRIB_DIR/garm.service /etc/systemd/system/garm.service -systemctl daemon-reload -systemctl start garm +sudo systemctl daemon-reload +sudo systemctl start garm wait_open_port 127.0.0.1 9997 From d02292bd1aa78403cbcb44b17b7f4f874b3f0361 Mon Sep 17 00:00:00 2001 From: Gabriel Adrian Samfira Date: Wed, 2 Aug 2023 17:22:25 +0300 Subject: [PATCH 2/3] Fix config dir location Signed-off-by: Gabriel Adrian Samfira --- .github/workflows/integration-tests.yml | 3 +-- test/integration/scripts/setup-garm.sh | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/integration-tests.yml b/.github/workflows/integration-tests.yml index d0209a5c..835a4e1c 100644 --- a/.github/workflows/integration-tests.yml +++ b/.github/workflows/integration-tests.yml @@ -42,12 +42,11 @@ jobs: - name: Set up ngrok id: ngrok - uses: gabriel-samfira/ngrok-tunnel-action@v1.0 + uses: gabriel-samfira/ngrok-tunnel-action@867169320326b49398c565de3b3f0ee75fb1599a with: ngrok_authtoken: ${{ secrets.NGROK_AUTH_TOKEN }} port: 9997 tunnel_type: http - - name: Run integration tests run: go run ./test/integration/e2e.go diff --git a/test/integration/scripts/setup-garm.sh b/test/integration/scripts/setup-garm.sh index 0811ae0f..46f3e51b 100755 --- a/test/integration/scripts/setup-garm.sh +++ b/test/integration/scripts/setup-garm.sh @@ -4,7 +4,7 @@ set -o errexit DIR="$(dirname $0)" BINARIES_DIR="$PWD/bin" CONTRIB_DIR="$PWD/contrib" -CONFIG_DIR="$PWD/config" +CONFIG_DIR="$PWD/test/integration/config" if [[ ! -f $BINARIES_DIR/garm ]] || [[ ! -f $BINARIES_DIR/garm-cli ]]; then echo "ERROR: Please build GARM binaries first" From 9927a18b9aa1dd4547948740679bbe2a7476677a Mon Sep 17 00:00:00 2001 From: Gabriel Adrian Samfira Date: Wed, 2 Aug 2023 17:34:00 +0300 Subject: [PATCH 3/3] Update ngrok action Signed-off-by: Gabriel Adrian Samfira --- .github/workflows/integration-tests.yml | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/.github/workflows/integration-tests.yml b/.github/workflows/integration-tests.yml index 835a4e1c..a7283c9b 100644 --- a/.github/workflows/integration-tests.yml +++ b/.github/workflows/integration-tests.yml @@ -36,13 +36,22 @@ jobs: function randomStringGenerator() { tr -dc "a-zA-Z0-9@#$%^&*()_+?><~\`;'" > $GITHUB_ENV - echo "REPO_WEBHOOK_SECRET=$(randomStringGenerator)" >> $GITHUB_ENV - echo "ORG_WEBHOOK_SECRET=$(randomStringGenerator)" >> $GITHUB_ENV + + GARM_PASSWORD=$(randomStringGenerator) + REPO_WEBHOOK_SECRET=$(randomStringGenerator) + ORG_WEBHOOK_SECRET=$(randomStringGenerator) + + echo "::add-mask::$GARM_PASSWORD" + echo "::add-mask::$REPO_WEBHOOK_SECRET" + echo "::add-mask::$ORG_WEBHOOK_SECRET" + + echo "GARM_PASSWORD=$GARM_PASSWORD" >> $GITHUB_ENV + echo "REPO_WEBHOOK_SECRET=$REPO_WEBHOOK_SECRET" >> $GITHUB_ENV + echo "ORG_WEBHOOK_SECRET=$ORG_WEBHOOK_SECRET" >> $GITHUB_ENV - name: Set up ngrok id: ngrok - uses: gabriel-samfira/ngrok-tunnel-action@867169320326b49398c565de3b3f0ee75fb1599a + uses: gabriel-samfira/ngrok-tunnel-action@v1.1 with: ngrok_authtoken: ${{ secrets.NGROK_AUTH_TOKEN }} port: 9997