From df837e13f5db207c165e549afed54438263ea367 Mon Sep 17 00:00:00 2001 From: zfong Date: Mon, 25 Nov 2024 14:29:42 -0800 Subject: [PATCH] [cueweb] Add tests to ci/cd pipeline - Adding cueweb tests to the opencue ci/cd pipeline --- .github/workflows/testing-pipeline.yml | 99 ++++++++++++++++++++++- rest_gateway/Dockerfile | 24 ++++-- rest_gateway/opencue_gateway/main_test.go | 5 +- 3 files changed, 119 insertions(+), 9 deletions(-) diff --git a/.github/workflows/testing-pipeline.yml b/.github/workflows/testing-pipeline.yml index bcbbb7706..533f62916 100644 --- a/.github/workflows/testing-pipeline.yml +++ b/.github/workflows/testing-pipeline.yml @@ -2,9 +2,9 @@ name: OpenCue Testing Pipeline on: push: - branches: [ master ] + branches: [ master, cueweb ] pull_request: - branches: [ master ] + branches: [ master, cueweb ] jobs: test_python_2022: @@ -104,6 +104,101 @@ jobs: - name: Run Sphinx build run: ci/build_sphinx_docs.sh + test_cueweb: + name: Run CueWeb Tests + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v2 + - name: Use Node.js + uses: actions/setup-node@v1 + with: + node-version: 21.x + - name: install dependencies for cueweb + run: npm install + working-directory: ./cueweb + - name: Run tests in Docker container + run: npm test + working-directory: ./cueweb + test_rest_gateway: + name: Run Rest Gateway Tests + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v3 + - name: Set up Go + uses: actions/setup-go@v3 + with: + go-version: '1.21' + - name: Install Protobuf + run: | + sudo apt-get install -y protobuf-compiler + npm install -g protobuf-compiler + working-directory: ./rest_gateway/opencue_gateway + - name: Install dependencies + run: go mod init opencue_gateway && go mod tidy + working-directory: ./rest_gateway/opencue_gateway + - name: Install Go tools + run: | + go install github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway + go install github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2 + go install github.com/golang-jwt/jwt/v5 + go install google.golang.org/protobuf/cmd/protoc-gen-go + go install google.golang.org/grpc/cmd/protoc-gen-go-grpc + working-directory: ./rest_gateway/opencue_gateway + - name: Copy proto files + run: | + cp -r ./proto /app/proto + - name: Copy gateway files + run: | + cp -r ./rest_gateway/opencue_gateway /app/opencue_gateway + - name: Generate go grpc code + run: | + mkdir -p gen/go && \ + protoc -I ../proto/ \ + --go_out ./gen/go/ \ + --go_opt paths=source_relative \ + --go-grpc_out ./gen/go/ \ + --go-grpc_opt paths=source_relative \ + ../proto/*.proto + working-directory: ./rest_gateway/opencue_gateway + - name: Generate grpc-gateway handlers + run: | + protoc -I ../proto/ --grpc-gateway_out ./gen/go \ + --grpc-gateway_opt paths=source_relative \ + --grpc-gateway_opt generate_unbound_methods=true \ + ../proto/*.proto + working-directory: ./rest_gateway/opencue_gateway + - name: Run Go Unit Tests + run: go test -v + working-directory: ./rest_gateway/opencue_gateway +# test_rest_gateway: +# name: Run Rest Gateway Tests +# runs-on: ubuntu-latest +# steps: +# - name: Checkout repository +# uses: actions/checkout@v2 +# - name: Setup Go +# uses: actions/setup-go@v3 +# with: +# go-version: '1.21' +# - name: Initialize go module and install dependencies +# run: | +# cd rest_gateway/opencue_gateway +# go mod init opencue_gateway && go mod tidy +# - name: Install protoc-gen-groc-gateway tool +# run: | +# go install \ +# github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway@latest \ +# github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2@latest \ +# github.com/golang-jwt/jwt/v5@latest \ +# google.golang.org/protobuf/cmd/protoc-gen-go@latest \ +# google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest +# - name: Run rest gateway tests +# run: | +# cd rest_gateway/opencue_gateway +# go test -v ./... + check_changed_files: name: Check Changed Files runs-on: ubuntu-latest diff --git a/rest_gateway/Dockerfile b/rest_gateway/Dockerfile index c70b966c8..337b26f3e 100644 --- a/rest_gateway/Dockerfile +++ b/rest_gateway/Dockerfile @@ -1,9 +1,16 @@ -FROM centos7.6-go1.21:latest AS build +# Use the official CentOS 7 image +FROM registry.access.redhat.com/ubi9/ubi:latest AS build + +RUN dnf -y update && \ + dnf install -y git \ + golang \ + dnf-plugins-core \ + unzip + +RUN curl -LO https://github.com/protocolbuffers/protobuf/releases/download/v25.1/protoc-25.1-linux-x86_64.zip && \ + unzip protoc-25.1-linux-x86_64.zip -d /usr/local && \ + rm protoc-25.1-linux-x86_64.zip -RUN yum install -y \ - git \ - protobuf3-compiler \ - && yum clean all WORKDIR /app ENV PATH=$PATH:/root/go/bin:/opt/protobuf3/usr/bin/ @@ -38,13 +45,18 @@ RUN protoc -I ../proto/ --grpc-gateway_out ./gen/go \ --grpc-gateway_opt generate_unbound_methods=true \ ../proto/*.proto +# Environment variables for the rest gateway +ENV CUEBOT_ENDPOINT=tobefilledmanually +ENV REST_PORT=tobefilledmanually +ENV JWT_AUTH_SECRET=tobefilledmanually + # Uncomment this to run go tests # RUN go test -v # Build project RUN go build -o grpc_gateway main.go -FROM centos-7.6.1810:latest +FROM registry.access.redhat.com/ubi9/ubi:latest COPY --from=build /app/opencue_gateway/grpc_gateway /app/ # Ensure logs folder is created and has correct permissions diff --git a/rest_gateway/opencue_gateway/main_test.go b/rest_gateway/opencue_gateway/main_test.go index 18878dec8..322cfcdab 100644 --- a/rest_gateway/opencue_gateway/main_test.go +++ b/rest_gateway/opencue_gateway/main_test.go @@ -3,14 +3,17 @@ package main import ( "net/http" "net/http/httptest" + "os" "testing" "time" - + "github.com/golang-jwt/jwt/v5" "github.com/stretchr/testify/assert" ) func TestJwtMiddleware(t *testing.T) { + os.Setenv("CUEBOT_ENDPOINT", "test_endpoint") + os.Setenv("REST_PORT", "test_port") jwtSecret := []byte("test_secret") // Set up a sample handler to use with the middleware