diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml new file mode 100644 index 00000000..7a95a143 --- /dev/null +++ b/.github/workflows/cd.yml @@ -0,0 +1,58 @@ +name: CD + +on: + workflow_call: + secrets: + SSL_KEY: + required: true + SSL_CERT: + required: true + ENV_FILE: + required: true + workflow_dispatch: # Allows manual triggering of the workflow + +permissions: + packages: write + +jobs: + build_and_push: + runs-on: ubuntu-latest + environment: Test + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Create certs directory + run: mkdir certs + + - name: Write SSL key + run: echo "${{ secrets.SSL_KEY }}" > certs/ssl.key + + - name: Write SSL cert + run: echo "${{ secrets.SSL_CERT }}" > certs/ssl.cert + + - name: Write ENV file + run: echo "${{ secrets.ENV_FILE }}" > .env + + - name: Build and export + uses: docker/build-push-action@v6 + env: + DOCKER_BUILD_SUMMARY: false + with: + tags: ghcr.io/decatur-robotics/gearbox:latest + outputs: type=docker,dest=/tmp/gearbox.tar + context: . # Needed for Docker to find files made during the workflow + + - name: Load image + run: | + docker load --input /tmp/gearbox.tar + docker image ls -a + + - name: Sign in to GHCR + run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u decatur-robotics --password-stdin + + - name: Push to GHCR + run: docker push ghcr.io/decatur-robotics/gearbox:latest \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..c2661830 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,41 @@ +name: CI + +on: + pull_request: + branches: + - main + workflow_call: + workflow_dispatch: # Allows manual triggering of the workflow + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Build and export + uses: docker/build-push-action@v6 + with: + tags: ghcr.io/decatur-robotics/gearbox:latest + outputs: type=docker,dest=/tmp/gearbox.tar + + unit_test: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up Node.js + uses: actions/setup-node@v2 + with: + node-version: '20' + + - name: Install dependencies + run: npm install + + - name: Unit Tests + run: npm run test \ No newline at end of file diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml deleted file mode 100644 index cda1f03a..00000000 --- a/.github/workflows/cicd.yml +++ /dev/null @@ -1,76 +0,0 @@ -name: CI/CD - -on: - push: - branches: - - main - pull_request: - branches: - - main - workflow_dispatch: # Allows manual triggering of the workflow - -jobs: - build: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - - name: Build and export - uses: docker/build-push-action@v6 - with: - tags: ghcr.io/decatur-robotics/gearbox:latest - outputs: type=docker,dest=/tmp/gearbox.tar - - - name: Upload artifact - uses: actions/upload-artifact@v4 - with: - name: gearbox - path: /tmp/gearbox.tar - - unit_test: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Set up Node.js - uses: actions/setup-node@v2 - with: - node-version: '20' - - - name: Install dependencies - run: npm install - - - name: Unit Tests - run: npm run test - - push_to_ghcr: - runs-on: ubuntu-latest - if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} - needs: - - build - - unit_test - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Download artifact - uses: actions/download-artifact@v4 - with: - name: gearbox - path: /tmp - - - name: Load image - run: | - docker load --input /tmp/gearbox.tar - docker image ls -a - - - name: Sign in to GHCR - run: echo "${{ secrets.GHCR_TOKEN }}" | docker login ghcr.io -u decatur-robotics --password-stdin - - - name: Push to GHCR - run: docker push ghcr.io/decatur-robotics/gearbox:latest \ No newline at end of file diff --git a/.github/workflows/onpush.yml b/.github/workflows/onpush.yml new file mode 100644 index 00000000..16929e5a --- /dev/null +++ b/.github/workflows/onpush.yml @@ -0,0 +1,20 @@ +name: On Push + +on: + push: + branches: + - main + workflow_dispatch: # Allows manual triggering of the workflow + +jobs: + ci: + uses: ./.github/workflows/ci.yml + + cd: + needs: + - ci + uses: ./.github/workflows/cd.yml + secrets: + SSL_KEY: ${{ secrets.SSL_KEY }} + SSL_CERT: ${{ secrets.SSL_CERT }} + ENV_FILE: ${{ secrets.ENV_FILE }} \ No newline at end of file diff --git a/.gitignore b/.gitignore index 658bc761..04cafac3 100644 --- a/.gitignore +++ b/.gitignore @@ -40,4 +40,6 @@ next-env.d.ts /public/sw.js /public/sw.js.map /public/workbox-* -/public/fallback-* \ No newline at end of file +/public/fallback-* + +/certs/*.* \ No newline at end of file diff --git a/README.md b/README.md index c90b8425..fb95b66c 100644 --- a/README.md +++ b/README.md @@ -24,10 +24,8 @@ Features full feature parity with SJ2, whilst remaining simpler, faster and cool - NPM - A MongoDB instance - We use Atlas -- An SSL certificate saved as `localhost-key.pem` and `localhost.pem` +- An SSL certificate saved as `certs/key.pem` and `certs/cert.pem` - Can be generated with OpenSSL -- An SSL certificate saved as `production-key.pem` and `production.pem` - - This can be the same as the development certificate above - Secrets: - A Blue Alliance API key - An Orange Alliance API key @@ -67,4 +65,4 @@ We recommend you start with issues labelled `good first issue` to get a feel for Made with [contrib.rocks](https://contrib.rocks). ## Licensed under a CC BY-NC-SA 4.0 license -Read the license [here](LICENSE.md). \ No newline at end of file +Read the license [here](LICENSE.md). diff --git a/certs/localhost-key.pem b/certs/localhost-key.pem deleted file mode 100644 index e2a14c23..00000000 --- a/certs/localhost-key.pem +++ /dev/null @@ -1,28 +0,0 @@ ------BEGIN PRIVATE KEY----- -MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQC8/fJcFm48w6xL -sEGy2YO+9E2Z6htJK6xrZjnNNjGCWgSIAA9ucdXlh2hU1SMwGHMMhMIBlN6cHJLP -giMCcanw8QSZysD0vqAayWX8KllxyDhu/x4CDDy+qlU/kJyb/h+wvdTmTdze4IJb -PEgRSvwfAI2Z+4Z8llH0tF5vumarNgcc3MhCYP+gN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UF7gv2A2WNUpLufFUBrbdU2jUE4lmoKPYZ3f6cOS0x3VWXGQ/1K1PcQhyaYDPD1 -ZGE8YOo2k0Imn2MytlmhND+g2BuVhrCDi3Xbc8gI/bKCbrvM+ZSVPABC5Mle5a+3 -ih0S/noj3uBP1rMOH/PgFG3Mi5sPreRXwR7ibeUCgYAAsDA0v8igGWgjGijr/Umk -lw8QvBVO7H+xQMKkAgxhgGrXMdy2ctHm1c1CaU/2GUJKCjt7iLks3FbMkh8DC08E -SkRXe/Po21xVkN72kMnJFRCd6xfTYxWy7+SvIn/hW6NPLaemPrAdCLG/Oh/POoqs -PdeRarxK6Bm41Lj+rErheA== ------END PRIVATE KEY----- diff --git a/certs/localhost.pem b/certs/localhost.pem deleted file mode 100644 index 7a9fa993..00000000 --- a/certs/localhost.pem +++ /dev/null @@ -1,28 +0,0 @@ ------BEGIN CERTIFICATE----- -MIIExzCCAy+gAwIBAgIRAJd3DtWZH47gx195IWiwQWcwDQYJKoZIhvcNAQELBQAw -ga0xHjAcBgNVBAoTFW1rY2VydCBkZXZlbG9wbWVudCBDQTFBMD8GA1UECww4TEFQ -VE9QLUxCNjFRUlJJXHJkZGVsQExBUFRPUC1MQjYxUVJSSSAoUmVuYXRvIERlbGwn -T3NzbykxSDBGBgNVBAMMP21rY2VydCBMQVBUT1AtTEI2MVFSUklccmRkZWxATEFQ -VE9QLUxCNjFRUlJJIChSZW5hdG8gRGVsbCdPc3NvKTAeFw0yNDA2MjUxNTUwMTFa -Fw0yNjA5MjUxNTUwMTFaMGwxJzAlBgNVBAoTHm1rY2VydCBkZXZlbG9wbWVudCBj -ZXJ0aWZpY2F0ZTFBMD8GA1UECww4TEFQVE9QLUxCNjFRUlJJXHJkZGVsQExBUFRP -UC1MQjYxUVJSSSAoUmVuYXRvIERlbGwnT3NzbykwggEiMA0GCSqGSIb3DQEBAQUA -A4IBDwAwggEKAoIBAQC8/fJcFm48w6xLsEGy2YO+9E2Z6htJK6xrZjnNNjGCWgSI -AA9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lGte0Upi4SpaesT ------END CERTIFICATE----- diff --git a/index.ts b/index.ts index 31b8429f..cfbb62be 100644 --- a/index.ts +++ b/index.ts @@ -2,7 +2,7 @@ import { join } from "path"; import { createServer } from "https"; import { parse } from "url"; import next from "next"; -import fs from "fs"; +import fs, { readFileSync } from "fs"; import { App } from "@slack/bolt"; import SlackCommands from "./lib/SlackCommands"; import { IncomingMessage, ServerResponse, request } from "http"; @@ -18,17 +18,13 @@ const handle = app.getRequestHandler(); console.log("Constants set"); const httpsOptions = { - key: dev - ? fs.readFileSync("./certs/localhost-key.pem") - : fs.readFileSync("./certs/production-key.pem"), - cert: dev - ? fs.readFileSync("./certs/localhost.pem") - : fs.readFileSync("./certs/production.pem"), + key: readFileSync("./certs/key.pem"), + cert: readFileSync("./certs/cert.pem"), }; console.log("HTTPS options set"); -startSlackApp(); +// startSlackApp(); console.log("App preparing..."); app.prepare().then(() => { diff --git a/lib/TheBlueAlliance.ts b/lib/TheBlueAlliance.ts index f05674d8..80fd1464 100644 --- a/lib/TheBlueAlliance.ts +++ b/lib/TheBlueAlliance.ts @@ -312,7 +312,6 @@ export namespace TheBlueAlliance { async loadCompetitionPairings() { if (global?.compIdPairs) { - console.log("using cache..."); this.competitionPairings = global.compIdPairs; } else { console.log("Loading Pairings For Competition Searches..."); diff --git a/pages/createTeam.tsx b/pages/createTeam.tsx index 03f9aec8..9b8f882a 100644 --- a/pages/createTeam.tsx +++ b/pages/createTeam.tsx @@ -39,12 +39,7 @@ export default function CreateTeam() { } const findResult = await api.findTeamByNumberAndLeague(Number(team?.number), team.league); - if (!findResult) { - setError("Failed to check if team already exists. Please try again later."); - return; - } - - if (findResult._id) { + if (findResult?._id) { setError("This Team Already Exists"); return; }