From 2f2a35dcd40dd14be70c27ed3ff0c017c5adccc6 Mon Sep 17 00:00:00 2001 From: moreal Date: Tue, 14 May 2024 08:56:15 +0900 Subject: [PATCH 1/6] ci: deploy Docker image for every push on main branch --- .github/workflows/docker.yaml | 36 +++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 .github/workflows/docker.yaml diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml new file mode 100644 index 0000000..14d2d7e --- /dev/null +++ b/.github/workflows/docker.yaml @@ -0,0 +1,36 @@ +name: push docker image + +on: + push: + branches: + - "main" + +jobs: + build_and_push: + name: build_and_push (${{ matrix.docker.repo }}) + strategy: + matrix: + docker: + - repo: planetariumhq/9c-board + if: github.ref_type == 'branch' + runs-on: ubuntu-latest + steps: + - name: checkout + uses: actions/checkout@v4 + with: + submodules: recursive + - name: login + run: | + docker login \ + --username '${{ secrets.DOCKER_USERNAME }}' \ + --password '${{ secrets.DOCKER_ACCESS_TOKEN }}' + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: build-and-push + run: | + docker buildx build . \ + --platform linux/arm64/v8,linux/amd64 \ + --tag ${{ matrix.docker.repo }}:git-${{ github.sha }} \ + --push From 76b045e2643e66f782b81acaf8a4274d37a4c1ea Mon Sep 17 00:00:00 2001 From: moreal Date: Tue, 14 May 2024 09:00:54 +0900 Subject: [PATCH 2/6] ci: check build --- .github/workflows/build.yaml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 .github/workflows/build.yaml diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml new file mode 100644 index 0000000..8ded435 --- /dev/null +++ b/.github/workflows/build.yaml @@ -0,0 +1,18 @@ +name: build + +on: + push: + pull_request: + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: checkout + uses: actions/checkout@v4 + with: + submodules: recursive + - run: corepack enable + - run: yarn install --immutable + - run: yarn codegen + - run: yarn build From 544d02dfa9124cf503c2a50a92f6da4b18f244e0 Mon Sep 17 00:00:00 2001 From: moreal Date: Tue, 14 May 2024 09:07:25 +0900 Subject: [PATCH 3/6] fix: remove edge configuration --- pages/[network]/tablesheet/index.tsx | 2 -- 1 file changed, 2 deletions(-) diff --git a/pages/[network]/tablesheet/index.tsx b/pages/[network]/tablesheet/index.tsx index c37e6b2..f7d0dcc 100644 --- a/pages/[network]/tablesheet/index.tsx +++ b/pages/[network]/tablesheet/index.tsx @@ -3,8 +3,6 @@ import Link from "next/link"; import { useRouter } from "next/router"; import { getSheetNames } from "../../tools/apiClient"; -export const config = { runtime: "edge" }; - export const getServerSideProps: GetServerSideProps = async (context) => { const network = context.query.network as string; From 715c884df05ffbd1c8ed949ea812d238d8182cae Mon Sep 17 00:00:00 2001 From: moreal Date: Tue, 14 May 2024 09:12:23 +0900 Subject: [PATCH 4/6] fix: check required environment lazy --- sdk.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/sdk.ts b/sdk.ts index 51136f2..551bde3 100644 --- a/sdk.ts +++ b/sdk.ts @@ -2,10 +2,6 @@ import { GetServerSidePropsContext } from "next/types"; import { getSdk } from "./generated/graphql-request"; import { GraphQLClient } from "graphql-request" -if (process.env.NETWORK_CONF_MAP === undefined) { - throw new Error("All required environment variables are not set."); -} - function parseNetworkConfMap(confMapString: string): Map> { const map = new Map(); for (const pair of confMapString.split(',')) { @@ -16,9 +12,14 @@ function parseNetworkConfMap(confMapString: string): Map { + if (process.env.NETWORK_CONF_MAP === undefined) { + throw new Error("All required environment variables are not set."); + } + + const networkToSdkMap = parseNetworkConfMap(process.env.NETWORK_CONF_MAP); + const network = context.query.network; if (typeof network !== "string") { throw new Error("Network name parameter is not a string."); From 3572225d61da886de6e2495b266669e670d47ff1 Mon Sep 17 00:00:00 2001 From: moreal Date: Tue, 14 May 2024 09:13:13 +0900 Subject: [PATCH 5/6] chore: remove unnecessary environment when building Docker image --- Dockerfile | 2 -- 1 file changed, 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 3b84132..28db45c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,3 @@ -ARG NETWORK_MAP FROM node:22-alpine AS base # Install dependencies only when needed @@ -26,7 +25,6 @@ COPY . . # Uncomment the following line in case you want to disable telemetry during the build. ENV NEXT_TELEMETRY_DISABLED 1 -ENV NETWORK_CONF_MAP ${NETWORK_MAP} RUN yarn build # Production image, copy all the files and run next From 089dbc2c62b3270d39aa9a886b33091eadaa479c Mon Sep 17 00:00:00 2001 From: moreal Date: Tue, 14 May 2024 09:16:10 +0900 Subject: [PATCH 6/6] fix: move non-react code to outside of pages directory --- pages/tools/apiClient.ts => apiClient.ts | 0 pages/[network]/tablesheet/[name].tsx | 2 +- pages/[network]/tablesheet/index.tsx | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-) rename pages/tools/apiClient.ts => apiClient.ts (100%) diff --git a/pages/tools/apiClient.ts b/apiClient.ts similarity index 100% rename from pages/tools/apiClient.ts rename to apiClient.ts diff --git a/pages/[network]/tablesheet/[name].tsx b/pages/[network]/tablesheet/[name].tsx index a7b2e5a..7367710 100644 --- a/pages/[network]/tablesheet/[name].tsx +++ b/pages/[network]/tablesheet/[name].tsx @@ -1,5 +1,5 @@ import type { NextPage, GetServerSideProps } from "next"; -import { getSheet } from "../../tools/apiClient"; +import { getSheet } from "../../../apiClient"; interface TableSheetPageProps { tableSheet: string | null; diff --git a/pages/[network]/tablesheet/index.tsx b/pages/[network]/tablesheet/index.tsx index f7d0dcc..e2be840 100644 --- a/pages/[network]/tablesheet/index.tsx +++ b/pages/[network]/tablesheet/index.tsx @@ -1,7 +1,7 @@ import type { NextPage, GetServerSideProps } from "next"; import Link from "next/link"; import { useRouter } from "next/router"; -import { getSheetNames } from "../../tools/apiClient"; +import { getSheetNames } from "../../../apiClient"; export const getServerSideProps: GetServerSideProps = async (context) => { const network = context.query.network as string;