From 8351c16bbdae42c0c3602c686e6c955bfa591c21 Mon Sep 17 00:00:00 2001 From: DeveloperDurp Date: Sat, 8 Apr 2023 14:46:35 -0500 Subject: [PATCH] docker --- .dockerignore | 3 + .github/workflows/docker-image.yml | 29 +++++ .gitignore | 1 - Dockerfile | 23 ++++ docs/docs.go | 180 +++++++++++++++++++++++++++++ docs/swagger.json | 157 +++++++++++++++++++++++++ docs/swagger.yaml | 110 ++++++++++++++++++ 7 files changed, 502 insertions(+), 1 deletion(-) create mode 100644 .dockerignore create mode 100644 .github/workflows/docker-image.yml create mode 100644 Dockerfile create mode 100644 docs/docs.go create mode 100644 docs/swagger.json create mode 100644 docs/swagger.yaml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..4e7477d --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +.env +.vscode +.idea \ No newline at end of file diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml new file mode 100644 index 0000000..c2a4a8d --- /dev/null +++ b/.github/workflows/docker-image.yml @@ -0,0 +1,29 @@ +name: Docker Image CI + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + + build: + + runs-on: ubuntu-latest + + steps: + - name: Checkout Code + uses: actions/checkout@v1 + - name: Login to GitHub Container Registry + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Build and Push Docker Image + uses: docker/build-push-action@v3 + with: + push: true # Will only build if this is not here + tags: | + ghcr.io/developerdurp/durpapi:latest diff --git a/.gitignore b/.gitignore index 44e8555..2e14aec 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ __debug_bin -docs .vscode .env .idea \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..046d82b --- /dev/null +++ b/Dockerfile @@ -0,0 +1,23 @@ +# Use golang:1.17 as the base image +FROM golang:1.20 + +ENV GOPATH /go +ENV PATH $PATH:$GOPATH/bin + +# Set the working directory inside the container +WORKDIR /app + +# Copy the Go project files into the container +COPY . . + +# Run swag init to generate Swagger documentation +RUN go install && go install github.com/swaggo/swag/cmd/swag@latest && swag init + +# Build the Go application inside the container +RUN go build -o main . + +# Expose the port the application listens on +EXPOSE 8080 + +# Run the application +CMD ["./main"] \ No newline at end of file diff --git a/docs/docs.go b/docs/docs.go new file mode 100644 index 0000000..392995c --- /dev/null +++ b/docs/docs.go @@ -0,0 +1,180 @@ +// Code generated by swaggo/swag. DO NOT EDIT. + +package docs + +import "github.com/swaggo/swag" + +const docTemplate = `{ + "schemes": {{ marshal .Schemes }}, + "swagger": "2.0", + "info": { + "description": "{{escape .Description}}", + "title": "{{.Title}}", + "termsOfService": "http://swagger.io/terms/", + "contact": { + "name": "API Support", + "url": "http://www.swagger.io/support", + "email": "support@swagger.io" + }, + "license": { + "name": "Apache 2.0", + "url": "http://www.apache.org/licenses/LICENSE-2.0.html" + }, + "version": "{{.Version}}" + }, + "host": "{{.Host}}", + "basePath": "{{.BasePath}}", + "paths": { + "/openai/general": { + "get": { + "description": "Ask ChatGPT a general question", + "consumes": [ + "application/json" + ], + "produces": [ + "text/plain" + ], + "tags": [ + "openai" + ], + "summary": "Gerneral ChatGPT", + "parameters": [ + { + "type": "string", + "description": "Ask ChatGPT a general question", + "name": "message", + "in": "query", + "required": true + } + ], + "responses": { + "200": { + "description": "response", + "schema": { + "type": "string" + } + } + } + } + }, + "/openai/travelagent": { + "get": { + "description": "Ask ChatGPT for suggestions as if it was a travel agent", + "consumes": [ + "application/json" + ], + "produces": [ + "text/plain" + ], + "tags": [ + "openai" + ], + "summary": "Travel Agent ChatGPT", + "parameters": [ + { + "type": "string", + "description": "Ask ChatGPT for suggestions as a travel agent", + "name": "message", + "in": "query", + "required": true + } + ], + "responses": { + "200": { + "description": "response", + "schema": { + "type": "string" + } + } + } + } + }, + "/unraid/powerusage": { + "get": { + "description": "Gets the PSU Data from unraid", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "unraid" + ], + "summary": "Unraid PSU Stats", + "responses": { + "200": { + "description": "response", + "schema": { + "type": "string" + } + } + } + } + } + }, + "securityDefinitions": { + "ApiKeyAuth": { + "description": "Description for what is this security definition being used", + "type": "apiKey", + "name": "Authorization", + "in": "header" + }, + "BasicAuth": { + "type": "basic" + }, + "OAuth2AccessCode": { + "type": "oauth2", + "flow": "accessCode", + "authorizationUrl": "https://example.com/oauth/authorize", + "tokenUrl": "https://example.com/oauth/token", + "scopes": { + "admin": "\t\t\t\t\t\t\tGrants read and write access to administrative information" + } + }, + "OAuth2Application": { + "type": "oauth2", + "flow": "application", + "tokenUrl": "https://example.com/oauth/token", + "scopes": { + "admin": "\t\t\t\t\t\t\tGrants read and write access to administrative information", + "write": "\t\t\t\t\t\t\tGrants write access" + } + }, + "OAuth2Implicit": { + "type": "oauth2", + "flow": "implicit", + "authorizationUrl": "https://example.com/oauth/authorize", + "scopes": { + "admin": "\t\t\t\t\t\t\tGrants read and write access to administrative information", + "write": "\t\t\t\t\t\t\tGrants write access" + } + }, + "OAuth2Password": { + "type": "oauth2", + "flow": "password", + "tokenUrl": "https://example.com/oauth/token", + "scopes": { + "admin": "\t\t\t\t\t\t\tGrants read and write access to administrative information", + "read": "\t\t\t\t\t\t\t\tGrants read access", + "write": "\t\t\t\t\t\t\tGrants write access" + } + } + } +}` + +// SwaggerInfo holds exported Swagger Info so clients can modify it +var SwaggerInfo = &swag.Spec{ + Version: "1.0", + Host: "localhost:8080", + BasePath: "/api/v1", + Schemes: []string{}, + Title: "DurpAPI", + Description: "This is a sample server celler server.", + InfoInstanceName: "swagger", + SwaggerTemplate: docTemplate, +} + +func init() { + swag.Register(SwaggerInfo.InstanceName(), SwaggerInfo) +} diff --git a/docs/swagger.json b/docs/swagger.json new file mode 100644 index 0000000..92033d9 --- /dev/null +++ b/docs/swagger.json @@ -0,0 +1,157 @@ +{ + "swagger": "2.0", + "info": { + "description": "This is a sample server celler server.", + "title": "DurpAPI", + "termsOfService": "http://swagger.io/terms/", + "contact": { + "name": "API Support", + "url": "http://www.swagger.io/support", + "email": "support@swagger.io" + }, + "license": { + "name": "Apache 2.0", + "url": "http://www.apache.org/licenses/LICENSE-2.0.html" + }, + "version": "1.0" + }, + "host": "localhost:8080", + "basePath": "/api/v1", + "paths": { + "/openai/general": { + "get": { + "description": "Ask ChatGPT a general question", + "consumes": [ + "application/json" + ], + "produces": [ + "text/plain" + ], + "tags": [ + "openai" + ], + "summary": "Gerneral ChatGPT", + "parameters": [ + { + "type": "string", + "description": "Ask ChatGPT a general question", + "name": "message", + "in": "query", + "required": true + } + ], + "responses": { + "200": { + "description": "response", + "schema": { + "type": "string" + } + } + } + } + }, + "/openai/travelagent": { + "get": { + "description": "Ask ChatGPT for suggestions as if it was a travel agent", + "consumes": [ + "application/json" + ], + "produces": [ + "text/plain" + ], + "tags": [ + "openai" + ], + "summary": "Travel Agent ChatGPT", + "parameters": [ + { + "type": "string", + "description": "Ask ChatGPT for suggestions as a travel agent", + "name": "message", + "in": "query", + "required": true + } + ], + "responses": { + "200": { + "description": "response", + "schema": { + "type": "string" + } + } + } + } + }, + "/unraid/powerusage": { + "get": { + "description": "Gets the PSU Data from unraid", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "unraid" + ], + "summary": "Unraid PSU Stats", + "responses": { + "200": { + "description": "response", + "schema": { + "type": "string" + } + } + } + } + } + }, + "securityDefinitions": { + "ApiKeyAuth": { + "description": "Description for what is this security definition being used", + "type": "apiKey", + "name": "Authorization", + "in": "header" + }, + "BasicAuth": { + "type": "basic" + }, + "OAuth2AccessCode": { + "type": "oauth2", + "flow": "accessCode", + "authorizationUrl": "https://example.com/oauth/authorize", + "tokenUrl": "https://example.com/oauth/token", + "scopes": { + "admin": "\t\t\t\t\t\t\tGrants read and write access to administrative information" + } + }, + "OAuth2Application": { + "type": "oauth2", + "flow": "application", + "tokenUrl": "https://example.com/oauth/token", + "scopes": { + "admin": "\t\t\t\t\t\t\tGrants read and write access to administrative information", + "write": "\t\t\t\t\t\t\tGrants write access" + } + }, + "OAuth2Implicit": { + "type": "oauth2", + "flow": "implicit", + "authorizationUrl": "https://example.com/oauth/authorize", + "scopes": { + "admin": "\t\t\t\t\t\t\tGrants read and write access to administrative information", + "write": "\t\t\t\t\t\t\tGrants write access" + } + }, + "OAuth2Password": { + "type": "oauth2", + "flow": "password", + "tokenUrl": "https://example.com/oauth/token", + "scopes": { + "admin": "\t\t\t\t\t\t\tGrants read and write access to administrative information", + "read": "\t\t\t\t\t\t\t\tGrants read access", + "write": "\t\t\t\t\t\t\tGrants write access" + } + } + } +} \ No newline at end of file diff --git a/docs/swagger.yaml b/docs/swagger.yaml new file mode 100644 index 0000000..7fafe6d --- /dev/null +++ b/docs/swagger.yaml @@ -0,0 +1,110 @@ +basePath: /api/v1 +host: localhost:8080 +info: + contact: + email: support@swagger.io + name: API Support + url: http://www.swagger.io/support + description: This is a sample server celler server. + license: + name: Apache 2.0 + url: http://www.apache.org/licenses/LICENSE-2.0.html + termsOfService: http://swagger.io/terms/ + title: DurpAPI + version: "1.0" +paths: + /openai/general: + get: + consumes: + - application/json + description: Ask ChatGPT a general question + parameters: + - description: Ask ChatGPT a general question + in: query + name: message + required: true + type: string + produces: + - text/plain + responses: + "200": + description: response + schema: + type: string + summary: Gerneral ChatGPT + tags: + - openai + /openai/travelagent: + get: + consumes: + - application/json + description: Ask ChatGPT for suggestions as if it was a travel agent + parameters: + - description: Ask ChatGPT for suggestions as a travel agent + in: query + name: message + required: true + type: string + produces: + - text/plain + responses: + "200": + description: response + schema: + type: string + summary: Travel Agent ChatGPT + tags: + - openai + /unraid/powerusage: + get: + consumes: + - application/json + description: Gets the PSU Data from unraid + produces: + - application/json + responses: + "200": + description: response + schema: + type: string + summary: Unraid PSU Stats + tags: + - unraid +securityDefinitions: + ApiKeyAuth: + description: Description for what is this security definition being used + in: header + name: Authorization + type: apiKey + BasicAuth: + type: basic + OAuth2AccessCode: + authorizationUrl: https://example.com/oauth/authorize + flow: accessCode + scopes: + admin: "\t\t\t\t\t\t\tGrants read and write access to administrative information" + tokenUrl: https://example.com/oauth/token + type: oauth2 + OAuth2Application: + flow: application + scopes: + admin: "\t\t\t\t\t\t\tGrants read and write access to administrative information" + write: "\t\t\t\t\t\t\tGrants write access" + tokenUrl: https://example.com/oauth/token + type: oauth2 + OAuth2Implicit: + authorizationUrl: https://example.com/oauth/authorize + flow: implicit + scopes: + admin: "\t\t\t\t\t\t\tGrants read and write access to administrative information" + write: "\t\t\t\t\t\t\tGrants write access" + type: oauth2 + OAuth2Password: + flow: password + scopes: + admin: "\t\t\t\t\t\t\tGrants read and write access to administrative information" + read: "\t\t\t\t\t\t\t\tGrants read access" + write: "\t\t\t\t\t\t\tGrants write access" + tokenUrl: https://example.com/oauth/token + type: oauth2 +swagger: "2.0"