diff --git a/.github/workflows/typespec.yml b/.github/workflows/typespec.yml index 8d9adaa33..0569f504a 100644 --- a/.github/workflows/typespec.yml +++ b/.github/workflows/typespec.yml @@ -7,10 +7,12 @@ on: - '**' paths : - 'typespec/**' + - VERSION pull_request: types: [opened, reopened, synchronize] paths: - 'typespec/**' + - VERSION permissions: contents: read @@ -30,7 +32,7 @@ jobs: node-version : '20.9.0' - name : Install tsp - run : npm install -g @typespec/compiler + run : npm install -g @typespec/compiler@0.64.0 - name : Validate tsp files run : | @@ -38,3 +40,18 @@ jobs: tsp install tsp compile . + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v1 + with: + aws-access-key-id: ${{secrets.TOWER_CI_AWS_ACCESS}} + aws-secret-access-key: ${{secrets.TOWER_CI_AWS_SECRET}} + aws-region: eu-west-1 + + - name : Login to Amazon ECR + id : login-ecr + uses : aws-actions/amazon-ecr-login@v1 + + - name: Release OpenAPI docs + if: "contains(github.event.head_commit.message, '[release]')" + run: | + bash typespec/tag-and-push-openapi.sh diff --git a/src/main/groovy/io/seqera/wave/controller/ServiceInfoController.groovy b/src/main/groovy/io/seqera/wave/controller/ServiceInfoController.groovy index 7f0a895e4..85d43dd4a 100644 --- a/src/main/groovy/io/seqera/wave/controller/ServiceInfoController.groovy +++ b/src/main/groovy/io/seqera/wave/controller/ServiceInfoController.groovy @@ -59,4 +59,9 @@ class ServiceInfoController { : HttpResponse.badRequest() } + @Get(uri = "/openapi") + HttpResponse getOpenAPI() { + HttpResponse.redirect(URI.create("/openapi/")) + } + } diff --git a/src/test/groovy/io/seqera/wave/controller/ServiceInfoControllerTest.groovy b/src/test/groovy/io/seqera/wave/controller/ServiceInfoControllerTest.groovy new file mode 100644 index 000000000..c79ef7d91 --- /dev/null +++ b/src/test/groovy/io/seqera/wave/controller/ServiceInfoControllerTest.groovy @@ -0,0 +1,44 @@ +/* + * Wave, containers provisioning service + * Copyright (c) 2024, Seqera Labs + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package io.seqera.wave.controller + +import spock.lang.Specification + +import io.micronaut.http.HttpResponse +import io.micronaut.http.HttpStatus + +/** + * + * @author Munish Chouhan + */ +class ServiceInfoControllerTest extends Specification { + + def 'should redirect to /openapi/'() { + given: + def controller = new ServiceInfoController() + + when: + HttpResponse response = controller.getOpenAPI() + + then: + response.status == HttpStatus.MOVED_PERMANENTLY + response.header('Location') == '/openapi/' + } + +} diff --git a/typespec/Dockerfile b/typespec/Dockerfile new file mode 100644 index 000000000..27406b762 --- /dev/null +++ b/typespec/Dockerfile @@ -0,0 +1,10 @@ +FROM nginxinc/nginx-unprivileged:alpine + +# Copy index.html and openapi.yaml to the Nginx html directory +COPY index.html /usr/share/nginx/html/openapi/index.html +COPY tsp-output/@typespec/openapi3/openapi.yaml /usr/share/nginx/html/openapi/openapi.yaml + +# Expose port 8080 +EXPOSE 8080 + +CMD ["nginx", "-g", "daemon off;"] diff --git a/typespec/index.html b/typespec/index.html new file mode 100644 index 000000000..ded110fe8 --- /dev/null +++ b/typespec/index.html @@ -0,0 +1,28 @@ + + + + + + Wave API Documentation + + + +
+ + + + + diff --git a/typespec/main.tsp b/typespec/main.tsp index 6633a9e30..70e12ade2 100644 --- a/typespec/main.tsp +++ b/typespec/main.tsp @@ -1,4 +1,5 @@ import "@typespec/http"; import "@typespec/rest"; import "@typespec/openapi3"; +import "@typespec/versioning"; import "./routes.tsp"; diff --git a/typespec/package.json b/typespec/package.json index 5e792742d..8ffabbe64 100644 --- a/typespec/package.json +++ b/typespec/package.json @@ -1,12 +1,12 @@ { "name": "wave", - "version": "1.8.2", + "version": "1.16.7", "type": "module", "dependencies": { - "@typespec/compiler": "latest", - "@typespec/http": "latest", - "@typespec/rest": "latest", - "@typespec/openapi3": "latest" + "@typespec/compiler": "0.64.0", + "@typespec/http": "0.64.0", + "@typespec/openapi3": "0.64.0", + "@typespec/rest": "0.64.0" }, "private": true -} \ No newline at end of file +} diff --git a/typespec/routes.tsp b/typespec/routes.tsp index feb9d2045..7f4f41cb9 100644 --- a/typespec/routes.tsp +++ b/typespec/routes.tsp @@ -2,12 +2,19 @@ import "./models/models.tsp"; using TypeSpec.Http; using TypeSpec.Rest; +using TypeSpec.Versioning; +@versioned(wave.Versions) @service({ - title: "Wave service", + title: "Wave service" }) -@server("https://wave.seqera.io", "wave endopint") +@server("https://wave.dev-tower.net", "wave dev endpoint") +@server("https://wave.stage-seqera.io", "wave stage endpoint") +@server("https://wave.seqera.io", "wave prod endpoint") namespace wave { + enum Versions { + v1: "0.0.0", + } @route("/v1alpha2/container") interface ContainerService { diff --git a/typespec/tag-and-push-openapi.sh b/typespec/tag-and-push-openapi.sh new file mode 100755 index 000000000..e2eb0327a --- /dev/null +++ b/typespec/tag-and-push-openapi.sh @@ -0,0 +1,39 @@ +#!/bin/bash +# +# Wave, containers provisioning service +# Copyright (c) 2023-2024, Seqera Labs +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# + +# Tag and and push the the GitHub repo and Docker images + +set -e +set -x + +SED=sed +[[ $(uname) == Darwin ]] && SED=gsed + +RELEASE=${RELEASE:-$(git show -s --format='%s' | $SED -rn 's/.*\[(release)\].*/\1/p')} + +if [[ $RELEASE ]]; then + TAG=v$(cat VERSION) + version=$(cat VERSION) + + cd typespec + sed -i "s/version: 0.0.0/version: $version/" "tsp-output/@typespec/openapi3/openapi.yaml" + + docker build -t 195996028523.dkr.ecr.eu-west-1.amazonaws.com/wave/openapi:$TAG . + docker push 195996028523.dkr.ecr.eu-west-1.amazonaws.com/wave/openapi:$TAG +fi diff --git a/typespec/tspconfig.yaml b/typespec/tspconfig.yaml index a3fe48f13..93d8663db 100644 --- a/typespec/tspconfig.yaml +++ b/typespec/tspconfig.yaml @@ -1,2 +1,5 @@ emit: - "@typespec/openapi3" +options: + "@typespec/openapi3": + output-file: openapi.yaml