diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..fb7aebf --- /dev/null +++ b/.dockerignore @@ -0,0 +1,17 @@ +.git +.github +.gitignore +LICENSE +README.md + +Tools/mssql-proxy/build +Tools/mssql-proxy/dist +Tools/mssql-proxy/.gitignore +Tools/mssql-proxy/*.spec + +Frontend/.angular +Frontend/.vscode +Frontend/dist +Frontend/node_modules +Frontend/.gitignore +Frontend/.editorconfig \ No newline at end of file diff --git a/.github/workflows/build-publish.yml b/.github/workflows/build-publish.yml deleted file mode 100644 index 19b4cde..0000000 --- a/.github/workflows/build-publish.yml +++ /dev/null @@ -1,27 +0,0 @@ -name: Create Publish - -on: - workflow_call: - workflow_dispatch: - -permissions: - contents: read - pages: write - id-token: write - -jobs: - tests: - uses: ./.github/workflows/build-test.yml - - deploy: - needs: [tests] - environment: - name: "github-pages" - url: ${{ steps.build-publish.outputs.page_url }} - runs-on: ubuntu-latest - steps: - - id: build-publish - uses: bitovi/github-actions-angular-to-github-pages@v1.0.0 - with: - path: dist/code-chef/browser - build_command: npm run build diff --git a/.github/workflows/build-release.yml b/.github/workflows/build-release.yml index eadcd98..cdfb47c 100644 --- a/.github/workflows/build-release.yml +++ b/.github/workflows/build-release.yml @@ -1,4 +1,4 @@ -name: Create Release +name: Build Release on: push: @@ -10,12 +10,16 @@ permissions: pages: write id-token: write +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + jobs: publish: - uses: ./.github/workflows/build-publish.yml + uses: ./.github/workflows/publish.yml release: - needs: [publish, build-linux, build-windows] + needs: [publish, build-linux, build-windows, build-docker] runs-on: ubuntu-latest steps: - name: Checkout @@ -35,6 +39,37 @@ jobs: mssql-proxy-${{ github.ref_name }}-linux.tar.gz mssql-proxy-${{ github.ref_name }}-windows.zip + # publish docker + - name: Install cosign + uses: sigstore/cosign-installer@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log into registry ${{ env.REGISTRY }} + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push Docker image + id: build-and-push + uses: docker/build-push-action@v6 + with: + context: . + push: true + tags: ${{ needs.build-docker.outputs.tags }} + labels: ${{ needs.build-docker.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max + + - name: Sign the published Docker image + env: + TAGS: ${{ needs.build-docker.outputs.tags }} + DIGEST: ${{ needs.build-docker.outputs.digest }} + run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST} + build-linux: runs-on: ubuntu-latest steps: @@ -67,4 +102,33 @@ jobs: name: build-windows path: mssql-proxy-${{ github.ref_name }}-windows.zip - # build-macos: + # build-macos: + + build-docker: + runs-on: linux-latest + outputs: + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + digest: ${{ steps.build-and-push.outputs.digest }} + steps: + - uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Extract Docker metadata + uses: docker/metadata-action@v5 + id: meta + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + + - name: Build and push Docker image + id: build-and-push + uses: docker/build-push-action@v6 + with: + context: . + push: false + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index dafeda1..a851f75 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -1,5 +1,5 @@ -name: Build and Test +name: Build Test on: pull_request: @@ -22,5 +22,13 @@ jobs: with: node-version: ${{ matrix.node }} - run: npm ci + working-directory: Frontend - run: npm run test-ci + working-directory: Frontend - run: npm run build + working-directory: Frontend + - uses: actions/upload-artifact@v4 + if: github.event_name != 'pull_request' + with: + name: codechef-build + path: Frontend/dist/code-chef diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..689e0d7 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,35 @@ +name: Publish + +on: + workflow_call: + workflow_dispatch: + +permissions: + contents: read + pages: write + id-token: write + +jobs: + build: + uses: ./.github/workflows/build-test.yml + + publish: + needs: [build] + environment: + name: "github-pages" + url: ${{ steps.deploy.outputs.page_url }} + runs-on: ubuntu-latest + steps: + - name: 'download build' + uses: actions/download-artifact@v4 + with: + name: codechef-build + - name: 'upload pages' + uses: actions/upload-pages-artifact@v3 + with: + path: code-chef/browser + - name: Deploy to GitHub Pages + id: deploy + uses: actions/deploy-pages@v4 + with: + token: ${{ github.token }} diff --git a/.gitignore b/.gitignore index cc7b141..240d33a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,16 +1,3 @@ -# See https://docs.github.com/get-started/getting-started-with-git/ignoring-files for more about ignoring files. - -# Compiled output -/dist -/tmp -/out-tsc -/bazel-out - -# Node -/node_modules -npm-debug.log -yarn-error.log - # IDEs and editors .idea/ .project @@ -28,15 +15,6 @@ yarn-error.log !.vscode/extensions.json .history/* -# Miscellaneous -/.angular/cache -.sass-cache/ -/connect.lock -/coverage -/libpeerconnection.log -testem.log -/typings - # System files .DS_Store Thumbs.db diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..aaecb52 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,36 @@ +FROM node:20-alpine AS node-builder + +WORKDIR /app + +COPY Frontend . + +RUN npm install +RUN npm run build + +FROM python:3.11-alpine AS python-builder + +WORKDIR /app + +RUN apk add --no-cache --update alpine-sdk +RUN apk add --no-cache gcc python3-dev musl-dev libffi-dev libc-dev unixodbc unixodbc-dev + +COPY Tools/mssql-proxy . +RUN pip install --no-cache-dir -r requirements.txt pyinstaller +RUN pyinstaller --onefile mssql-proxy.py --name mssql-proxy + +FROM alpine:latest + +RUN apk add --no-cache nginx + +COPY --from=node-builder /app/dist/code-chef /usr/share/nginx/code-chef +COPY --from=python-builder /app/dist/mssql-proxy /usr/local/bin/mssql-proxy + +COPY nginx.conf /etc/nginx/nginx.conf + +RUN mkdir -p /run/nginx /var/log/api + +ENV ALLOWED_ORIGIN="http://localhost:4200" + +EXPOSE 4200 50505 + +CMD ["sh", "-c", "nginx && /usr/local/bin/mssql-proxy -o ${ALLOWED_ORIGIN}"] diff --git a/.editorconfig b/Frontend/.editorconfig similarity index 100% rename from .editorconfig rename to Frontend/.editorconfig diff --git a/Frontend/.gitignore b/Frontend/.gitignore new file mode 100644 index 0000000..cc7b141 --- /dev/null +++ b/Frontend/.gitignore @@ -0,0 +1,42 @@ +# See https://docs.github.com/get-started/getting-started-with-git/ignoring-files for more about ignoring files. + +# Compiled output +/dist +/tmp +/out-tsc +/bazel-out + +# Node +/node_modules +npm-debug.log +yarn-error.log + +# IDEs and editors +.idea/ +.project +.classpath +.c9/ +*.launch +.settings/ +*.sublime-workspace + +# Visual Studio Code +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +.history/* + +# Miscellaneous +/.angular/cache +.sass-cache/ +/connect.lock +/coverage +/libpeerconnection.log +testem.log +/typings + +# System files +.DS_Store +Thumbs.db diff --git a/.vscode/extensions.json b/Frontend/.vscode/extensions.json similarity index 100% rename from .vscode/extensions.json rename to Frontend/.vscode/extensions.json diff --git a/.vscode/launch.json b/Frontend/.vscode/launch.json similarity index 100% rename from .vscode/launch.json rename to Frontend/.vscode/launch.json diff --git a/.vscode/settings.json b/Frontend/.vscode/settings.json similarity index 100% rename from .vscode/settings.json rename to Frontend/.vscode/settings.json diff --git a/.vscode/tasks.json b/Frontend/.vscode/tasks.json similarity index 100% rename from .vscode/tasks.json rename to Frontend/.vscode/tasks.json diff --git a/angular.json b/Frontend/angular.json similarity index 100% rename from angular.json rename to Frontend/angular.json diff --git a/package-lock.json b/Frontend/package-lock.json similarity index 100% rename from package-lock.json rename to Frontend/package-lock.json diff --git a/package.json b/Frontend/package.json similarity index 100% rename from package.json rename to Frontend/package.json diff --git a/public/code-chef.svg b/Frontend/public/code-chef.svg similarity index 100% rename from public/code-chef.svg rename to Frontend/public/code-chef.svg diff --git a/public/ipaf.svg b/Frontend/public/ipaf.svg similarity index 100% rename from public/ipaf.svg rename to Frontend/public/ipaf.svg diff --git a/server.ts b/Frontend/server.ts similarity index 100% rename from server.ts rename to Frontend/server.ts diff --git a/src/app/app.config.server.ts b/Frontend/src/app/app.config.server.ts similarity index 100% rename from src/app/app.config.server.ts rename to Frontend/src/app/app.config.server.ts diff --git a/src/app/app.config.ts b/Frontend/src/app/app.config.ts similarity index 100% rename from src/app/app.config.ts rename to Frontend/src/app/app.config.ts diff --git a/src/app/app.routes.ts b/Frontend/src/app/app.routes.ts similarity index 93% rename from src/app/app.routes.ts rename to Frontend/src/app/app.routes.ts index 828fa9a..f43a5e2 100644 --- a/src/app/app.routes.ts +++ b/Frontend/src/app/app.routes.ts @@ -16,4 +16,5 @@ export const routes: Routes = [ { path: 'downloads', title: "Downloads • CodeChef", component: DownloadsComponent }, { path: '**', title: "Not Found • CodeChef", component: NotFoundComponent }, + { path: '404', title: "Not Found • CodeChef", component: NotFoundComponent }, ]; diff --git a/src/app/app/app.component.html b/Frontend/src/app/app/app.component.html similarity index 100% rename from src/app/app/app.component.html rename to Frontend/src/app/app/app.component.html diff --git a/src/app/app/app.component.spec.ts b/Frontend/src/app/app/app.component.spec.ts similarity index 100% rename from src/app/app/app.component.spec.ts rename to Frontend/src/app/app/app.component.spec.ts diff --git a/src/app/app/app.component.ts b/Frontend/src/app/app/app.component.ts similarity index 100% rename from src/app/app/app.component.ts rename to Frontend/src/app/app/app.component.ts diff --git a/src/app/code-area/code-area.component.css b/Frontend/src/app/code-area/code-area.component.css similarity index 100% rename from src/app/code-area/code-area.component.css rename to Frontend/src/app/code-area/code-area.component.css diff --git a/src/app/code-area/code-area.component.spec.ts b/Frontend/src/app/code-area/code-area.component.spec.ts similarity index 100% rename from src/app/code-area/code-area.component.spec.ts rename to Frontend/src/app/code-area/code-area.component.spec.ts diff --git a/src/app/code-area/code-area.component.ts b/Frontend/src/app/code-area/code-area.component.ts similarity index 100% rename from src/app/code-area/code-area.component.ts rename to Frontend/src/app/code-area/code-area.component.ts diff --git a/src/app/cs2ts/cs2ts.component.html b/Frontend/src/app/cs2ts/cs2ts.component.html similarity index 100% rename from src/app/cs2ts/cs2ts.component.html rename to Frontend/src/app/cs2ts/cs2ts.component.html diff --git a/src/app/cs2ts/cs2ts.component.spec.ts b/Frontend/src/app/cs2ts/cs2ts.component.spec.ts similarity index 100% rename from src/app/cs2ts/cs2ts.component.spec.ts rename to Frontend/src/app/cs2ts/cs2ts.component.spec.ts diff --git a/src/app/cs2ts/cs2ts.component.ts b/Frontend/src/app/cs2ts/cs2ts.component.ts similarity index 100% rename from src/app/cs2ts/cs2ts.component.ts rename to Frontend/src/app/cs2ts/cs2ts.component.ts diff --git a/src/app/downloads/downloads.component.html b/Frontend/src/app/downloads/downloads.component.html similarity index 100% rename from src/app/downloads/downloads.component.html rename to Frontend/src/app/downloads/downloads.component.html diff --git a/src/app/downloads/downloads.component.spec.ts b/Frontend/src/app/downloads/downloads.component.spec.ts similarity index 100% rename from src/app/downloads/downloads.component.spec.ts rename to Frontend/src/app/downloads/downloads.component.spec.ts diff --git a/src/app/downloads/downloads.component.ts b/Frontend/src/app/downloads/downloads.component.ts similarity index 100% rename from src/app/downloads/downloads.component.ts rename to Frontend/src/app/downloads/downloads.component.ts diff --git a/src/app/footer/footer.component.css b/Frontend/src/app/footer/footer.component.css similarity index 100% rename from src/app/footer/footer.component.css rename to Frontend/src/app/footer/footer.component.css diff --git a/src/app/footer/footer.component.html b/Frontend/src/app/footer/footer.component.html similarity index 100% rename from src/app/footer/footer.component.html rename to Frontend/src/app/footer/footer.component.html diff --git a/src/app/footer/footer.component.spec.ts b/Frontend/src/app/footer/footer.component.spec.ts similarity index 100% rename from src/app/footer/footer.component.spec.ts rename to Frontend/src/app/footer/footer.component.spec.ts diff --git a/src/app/footer/footer.component.ts b/Frontend/src/app/footer/footer.component.ts similarity index 100% rename from src/app/footer/footer.component.ts rename to Frontend/src/app/footer/footer.component.ts diff --git a/src/app/header/header.component.css b/Frontend/src/app/header/header.component.css similarity index 100% rename from src/app/header/header.component.css rename to Frontend/src/app/header/header.component.css diff --git a/src/app/header/header.component.html b/Frontend/src/app/header/header.component.html similarity index 94% rename from src/app/header/header.component.html rename to Frontend/src/app/header/header.component.html index 7b8dcb7..b026ab8 100644 --- a/src/app/header/header.component.html +++ b/Frontend/src/app/header/header.component.html @@ -12,7 +12,7 @@

CodeChef

- Downloads + Downloads
diff --git a/src/app/header/header.component.spec.ts b/Frontend/src/app/header/header.component.spec.ts similarity index 100% rename from src/app/header/header.component.spec.ts rename to Frontend/src/app/header/header.component.spec.ts diff --git a/src/app/header/header.component.ts b/Frontend/src/app/header/header.component.ts similarity index 100% rename from src/app/header/header.component.ts rename to Frontend/src/app/header/header.component.ts diff --git a/src/app/home/home.component.html b/Frontend/src/app/home/home.component.html similarity index 100% rename from src/app/home/home.component.html rename to Frontend/src/app/home/home.component.html diff --git a/src/app/home/home.component.spec.ts b/Frontend/src/app/home/home.component.spec.ts similarity index 100% rename from src/app/home/home.component.spec.ts rename to Frontend/src/app/home/home.component.spec.ts diff --git a/src/app/home/home.component.ts b/Frontend/src/app/home/home.component.ts similarity index 100% rename from src/app/home/home.component.ts rename to Frontend/src/app/home/home.component.ts diff --git a/src/app/md2html/md2html.component.html b/Frontend/src/app/md2html/md2html.component.html similarity index 100% rename from src/app/md2html/md2html.component.html rename to Frontend/src/app/md2html/md2html.component.html diff --git a/src/app/md2html/md2html.component.spec.ts b/Frontend/src/app/md2html/md2html.component.spec.ts similarity index 100% rename from src/app/md2html/md2html.component.spec.ts rename to Frontend/src/app/md2html/md2html.component.spec.ts diff --git a/src/app/md2html/md2html.component.ts b/Frontend/src/app/md2html/md2html.component.ts similarity index 100% rename from src/app/md2html/md2html.component.ts rename to Frontend/src/app/md2html/md2html.component.ts diff --git a/src/app/mssql-scaffolder/mssql-scaffolder.component.html b/Frontend/src/app/mssql-scaffolder/mssql-scaffolder.component.html similarity index 100% rename from src/app/mssql-scaffolder/mssql-scaffolder.component.html rename to Frontend/src/app/mssql-scaffolder/mssql-scaffolder.component.html diff --git a/src/app/mssql-scaffolder/mssql-scaffolder.component.spec.ts b/Frontend/src/app/mssql-scaffolder/mssql-scaffolder.component.spec.ts similarity index 100% rename from src/app/mssql-scaffolder/mssql-scaffolder.component.spec.ts rename to Frontend/src/app/mssql-scaffolder/mssql-scaffolder.component.spec.ts diff --git a/src/app/mssql-scaffolder/mssql-scaffolder.component.ts b/Frontend/src/app/mssql-scaffolder/mssql-scaffolder.component.ts similarity index 98% rename from src/app/mssql-scaffolder/mssql-scaffolder.component.ts rename to Frontend/src/app/mssql-scaffolder/mssql-scaffolder.component.ts index 74e4f7d..6960568 100644 --- a/src/app/mssql-scaffolder/mssql-scaffolder.component.ts +++ b/Frontend/src/app/mssql-scaffolder/mssql-scaffolder.component.ts @@ -40,7 +40,7 @@ import { RouterLink } from '@angular/router'; export class MssqlScaffolderComponent { protected dbSettings: FormGroup = new FormGroup( { - proxy: new FormControl('localhost:50505', { nonNullable: true, validators: [Validators.required] }), + proxy: new FormControl('http://localhost:50505', { nonNullable: true, validators: [Validators.required] }), server: new FormControl('.', { nonNullable: true, validators: [Validators.required] }), username: new FormControl('', { nonNullable: true, validators: [Validators.required] }), password: new FormControl('', { nonNullable: true, validators: [Validators.required] }), @@ -129,7 +129,7 @@ export class MssqlScaffolderComponent { if (this.status == this.connectionStatus.disconnected) { this.status = this.connectionStatus.connecting; this.dbSettings.disable(); - MssqlService.apiUrl = `http://${this.dbSettings.controls["proxy"].value}`; + MssqlService.apiUrl = this.dbSettings.controls["proxy"].value; this.mssql.connect(this.dbSettings.getRawValue() as ConnectRequest).subscribe({ next: (res) => { res = res as ConnectResponse; diff --git a/src/app/mssql-scaffolder/mssql-scaffolder.model.ts b/Frontend/src/app/mssql-scaffolder/mssql-scaffolder.model.ts similarity index 100% rename from src/app/mssql-scaffolder/mssql-scaffolder.model.ts rename to Frontend/src/app/mssql-scaffolder/mssql-scaffolder.model.ts diff --git a/src/app/mssql-scaffolder/mssql-scaffolder.service.spec.ts b/Frontend/src/app/mssql-scaffolder/mssql-scaffolder.service.spec.ts similarity index 100% rename from src/app/mssql-scaffolder/mssql-scaffolder.service.spec.ts rename to Frontend/src/app/mssql-scaffolder/mssql-scaffolder.service.spec.ts diff --git a/src/app/mssql-scaffolder/mssql-scaffolder.service.ts b/Frontend/src/app/mssql-scaffolder/mssql-scaffolder.service.ts similarity index 100% rename from src/app/mssql-scaffolder/mssql-scaffolder.service.ts rename to Frontend/src/app/mssql-scaffolder/mssql-scaffolder.service.ts diff --git a/src/app/not-found/not-found.component.css b/Frontend/src/app/not-found/not-found.component.css similarity index 100% rename from src/app/not-found/not-found.component.css rename to Frontend/src/app/not-found/not-found.component.css diff --git a/src/app/not-found/not-found.component.html b/Frontend/src/app/not-found/not-found.component.html similarity index 100% rename from src/app/not-found/not-found.component.html rename to Frontend/src/app/not-found/not-found.component.html diff --git a/src/app/not-found/not-found.component.spec.ts b/Frontend/src/app/not-found/not-found.component.spec.ts similarity index 100% rename from src/app/not-found/not-found.component.spec.ts rename to Frontend/src/app/not-found/not-found.component.spec.ts diff --git a/src/app/not-found/not-found.component.ts b/Frontend/src/app/not-found/not-found.component.ts similarity index 100% rename from src/app/not-found/not-found.component.ts rename to Frontend/src/app/not-found/not-found.component.ts diff --git a/src/app/serialized-tool/serialized-tool.component.html b/Frontend/src/app/serialized-tool/serialized-tool.component.html similarity index 100% rename from src/app/serialized-tool/serialized-tool.component.html rename to Frontend/src/app/serialized-tool/serialized-tool.component.html diff --git a/src/app/serialized-tool/serialized-tool.component.spec.ts b/Frontend/src/app/serialized-tool/serialized-tool.component.spec.ts similarity index 100% rename from src/app/serialized-tool/serialized-tool.component.spec.ts rename to Frontend/src/app/serialized-tool/serialized-tool.component.spec.ts diff --git a/src/app/serialized-tool/serialized-tool.component.ts b/Frontend/src/app/serialized-tool/serialized-tool.component.ts similarity index 100% rename from src/app/serialized-tool/serialized-tool.component.ts rename to Frontend/src/app/serialized-tool/serialized-tool.component.ts diff --git a/src/index.html b/Frontend/src/index.html similarity index 100% rename from src/index.html rename to Frontend/src/index.html diff --git a/src/main.server.ts b/Frontend/src/main.server.ts similarity index 100% rename from src/main.server.ts rename to Frontend/src/main.server.ts diff --git a/src/main.ts b/Frontend/src/main.ts similarity index 100% rename from src/main.ts rename to Frontend/src/main.ts diff --git a/src/services/mssql/mssql.model.ts b/Frontend/src/services/mssql/mssql.model.ts similarity index 100% rename from src/services/mssql/mssql.model.ts rename to Frontend/src/services/mssql/mssql.model.ts diff --git a/src/services/mssql/mssql.service.spec.ts b/Frontend/src/services/mssql/mssql.service.spec.ts similarity index 100% rename from src/services/mssql/mssql.service.spec.ts rename to Frontend/src/services/mssql/mssql.service.spec.ts diff --git a/src/services/mssql/mssql.service.ts b/Frontend/src/services/mssql/mssql.service.ts similarity index 100% rename from src/services/mssql/mssql.service.ts rename to Frontend/src/services/mssql/mssql.service.ts diff --git a/src/styles.css b/Frontend/src/styles.css similarity index 100% rename from src/styles.css rename to Frontend/src/styles.css diff --git a/tsconfig.app.json b/Frontend/tsconfig.app.json similarity index 100% rename from tsconfig.app.json rename to Frontend/tsconfig.app.json diff --git a/tsconfig.json b/Frontend/tsconfig.json similarity index 100% rename from tsconfig.json rename to Frontend/tsconfig.json diff --git a/tsconfig.spec.json b/Frontend/tsconfig.spec.json similarity index 100% rename from tsconfig.spec.json rename to Frontend/tsconfig.spec.json diff --git a/README.md b/README.md index 5c7b8fe..ec07830 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@

-# CodeChef +# CodeChef CodeChef is an online developer tool that aims to eliminate repetitive developer tasks and automate what could be automated. @@ -16,15 +16,9 @@ CodeChef is an online developer tool that aims to eliminate repetitive developer - **Serialized tool**
Converts serialized objects between different formats(JSON, XML, YAML, TOML). - **MSSQL Scaffolder**
Scaffolds C# Models from MSSQL Tables and Stored Procedures. -## Usage - You can [**Go to Live Website**](https://codechef.ipdotsetaf.ir) or Run the website locally. -### MSSQL Proxy Server - -If you want to use any of the tools that need to communicate with MSSQL database, you need to download and run the proxy server, you can either download the binaries for your machine from the [**Release**](https://github.com/IPdotSetAF/CodeChef/releases) section or download the proxy [**Source Code**](https://github.com/IPdotSetAF/CodeChef/tree/main/CodeChefDatabaseProxy) and run it in your python environment. - -## Running CodeChef Locally +## Running CodeChef Frontend Locally This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 18.2.9. @@ -40,17 +34,57 @@ Run `npm run build` or `ng build` to build the project. The build artifacts will Run `npm run test` or `ng test` to execute the unit tests via [Karma](https://karma-runner.github.io). -## Running MSSQL Proxy Server +## MSSQL Proxy Server + +If you want to use any of the tools that need to communicate with MSSQL database, you need to download and run the proxy server, you can either download the binaries for your machine from the [**Release**](https://github.com/IPdotSetAF/CodeChef/releases) section or download the proxy [**Source Code**](https://github.com/IPdotSetAF/CodeChef/tree/main/CodeChefDatabaseProxy) and run it in your python environment. + +### Running MSSQL Proxy Server -### From precompiled binaries Just download the proper version from the [release section](https://github.com/IPdotSetAF/CodeChef/releases) and run it!! -### From Source Code -Follow these steps if you want to Run the proxy server from the Python source code: -1. Download the proxy server Python source code from the [release section](https://github.com/IPdotSetAF/CodeChef/releases). +#### Args +``` +-p --port +-o --allowed-origin +``` + +#### From Source Code +Follow these steps if you want to Run the mssql-proxy from the Python source code: +1. Download the mssql-proxy Python source code from the [release section](https://github.com/IPdotSetAF/CodeChef/releases). 3. `pip install -r requirements.txt` 4. `python proxy.py` +## Docker + +CodeChef docker image contains both the **Frontend** and **mssql-proxy**. + +### Pulling the image +```bash +docker pull ghcr.io/ipdotsetaf/codechef:latest +``` + +### Running the container +```bash +docker run --name codechef -d -p 4200:4200 -p 50505:50505 ghcr.io/ipdotsetaf/codechef:latest +``` + +#### Changing the Frontend port +```bash +docker run --name codechef -d -e ALLOWED_ORIGIN="http://localhost:" -p :4200 -p 50505:50505 ghcr.io/ipdotsetaf/codechef:latest +``` +The allowed origin will be the url that will serve the Fronend and the browser access it with. + +#### Changing the proxy +```bash +docker run --name codechef -d -p 4200:4200 -p :50505 ghcr.io/ipdotsetaf/codechef:latest +``` + +### Exposing database to mssql-proxy +> [!IMPORTANT] +> you need to make sure that codechef container and you mssql-server is on the same network and know the mssql-server ip address exposed on that network. that will be the ip address you use on CodeChef website. +#### Instructions +TBD... + ## TODO: - **Markdown preview** in Markdown to HTML Converter - MSSQL **Diff Tool** diff --git a/Tools/mssql-proxy/.gitignore b/Tools/mssql-proxy/.gitignore new file mode 100644 index 0000000..24603c8 --- /dev/null +++ b/Tools/mssql-proxy/.gitignore @@ -0,0 +1,17 @@ +# Compiled output +/dist +/build +*.spec + +# IDEs and editors +.idea/ +.project +.classpath +.c9/ +*.launch +.settings/ +*.sublime-workspace + +# System files +.DS_Store +Thumbs.db diff --git a/Tools/mssql-proxy/mssql-proxy.py b/Tools/mssql-proxy/mssql-proxy.py index 56e588e..30846dd 100644 --- a/Tools/mssql-proxy/mssql-proxy.py +++ b/Tools/mssql-proxy/mssql-proxy.py @@ -1,3 +1,4 @@ +import argparse import pyodbc import uuid from fastapi import FastAPI, HTTPException @@ -9,16 +10,20 @@ # Initialize colorama init(autoreset=True) -from fastapi.middleware.cors import CORSMiddleware +# Argument parsing for port and allowed origin +parser = argparse.ArgumentParser(description="Run the proxy server with customizable port and allowed origin.") +parser.add_argument("--port", "-p", type=int, default=50505, help="Port to run the server on (default: 50505)") +parser.add_argument("--allowed-origin", "-o", type=str, default="http://localhost:4200", help="Allowed CORS origin (default: http://localhost:4200)") +args = parser.parse_args() # Initialize FastAPI app app = FastAPI() +# Set allowed origins origins = [ "https://codechef.ipdotsetaf.ir", "https://ipdotsetaf.github.ir", - "http://localhost:4200" -] + args.allowed_origin] app.add_middleware( CORSMiddleware, @@ -150,4 +155,7 @@ async def disconnect(request: DisconnectRequest): # Run the FastAPI server if __name__ == "__main__": - uvicorn.run(app, host="0.0.0.0", port=50505, access_log=False) + portTxt = f"{Fore.BLUE}{args.port}{Style.RESET_ALL}" + originTxt = f"{Fore.BLUE}{args.allowed_origin}{Style.RESET_ALL}" + print(f"Starting server on port {portTxt} with allowed origin: {originTxt}") + uvicorn.run(app, host="0.0.0.0", port=args.port, access_log=False) \ No newline at end of file diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..d95c402 --- /dev/null +++ b/nginx.conf @@ -0,0 +1,16 @@ +events {} + +http { + include mime.types; + + server { + listen 0.0.0.0:4200; + listen [::]:4200; + + root /usr/share/nginx/code-chef/browser; + + location / { + try_files $uri $uri/ /404/index.html =404; + } + } +}