Skip to content

Commit 4c37e5f

Browse files
authored
fix(ci): update backend image build command (#1762)
* fix(ci): update backend image build command * refactor: cleanup rrule fix
1 parent 8715812 commit 4c37e5f

7 files changed

Lines changed: 70 additions & 18 deletions

File tree

.github/workflows/publish-docker-images.yml

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,22 @@ on:
1010
description: 'Semver tag to build, such as v1.2.3'
1111
required: true
1212
type: string
13+
push_images:
14+
description: 'Push built images to Docker Hub'
15+
required: false
16+
default: true
17+
type: boolean
1318
workflow_dispatch:
1419
inputs:
1520
tag:
1621
description: 'Semver tag to build, such as v1.2.3'
1722
required: true
1823
type: string
24+
push_images:
25+
description: 'Push built images to Docker Hub'
26+
required: false
27+
default: true
28+
type: boolean
1929

2030
permissions:
2131
contents: read
@@ -60,7 +70,7 @@ jobs:
6070
with:
6171
context: .
6272
file: self-host/Dockerfile.backend
63-
push: true
73+
push: ${{ github.event_name == 'push' || inputs.push_images }}
6474
tags: |
6575
switchbacktech/compass-backend:${{ steps.version.outputs.image_version }}
6676
switchbacktech/compass-backend:${{ steps.version.outputs.minor_tag }}
@@ -71,7 +81,7 @@ jobs:
7181
with:
7282
context: .
7383
file: self-host/Dockerfile.mongo
74-
push: true
84+
push: ${{ github.event_name == 'push' || inputs.push_images }}
7585
tags: |
7686
switchbacktech/compass-mongo:${{ steps.version.outputs.image_version }}
7787
switchbacktech/compass-mongo:${{ steps.version.outputs.minor_tag }}
@@ -82,7 +92,7 @@ jobs:
8292
with:
8393
context: .
8494
file: self-host/Dockerfile.web
85-
push: true
95+
push: ${{ github.event_name == 'push' || inputs.push_images }}
8696
# backend.apiUrl and google.clientId are baked into the web bundle at build time.
8797
# The published image ships with localhost defaults, which work for local installs.
8898
# Users who need a custom API domain or real Google credentials must rebuild

docs/CI-CD/cli-and-maintenance-commands.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ Seeders use the same migration framework and Mongo-backed execution state.
8888
Builds usually use direct package scripts:
8989

9090
- `bun run build:web`
91-
- `bun run build:backend --environment [local|staging|production]`
91+
- `bun run build:backend`
9292

9393
Use CLI build commands only when you specifically need their legacy packaging
9494
behavior.

packages/backend/src/event/classes/gcal.event.rrule.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,31 @@ describe("GcalEventRRule: ", () => {
6161
expect(events).toEqual(expect.arrayContaining([startDate.toDate()]));
6262
});
6363

64+
it("should not duplicate the base occurrence across timezone offsets", () => {
65+
const dates = {
66+
start: {
67+
dateTime: "2027-03-14T03:42:16-04:00",
68+
timeZone: "America/Indiana/Winamac",
69+
},
70+
end: {
71+
dateTime: "2027-03-14T04:42:16-04:00",
72+
timeZone: "America/Indiana/Winamac",
73+
},
74+
};
75+
const baseEvent = mockRecurringGcalBaseEvent(dates, false, {
76+
count: 3,
77+
freq: RRule.YEARLY,
78+
});
79+
const rrule = new GcalEventRRule(baseEvent);
80+
const instances = rrule.instances();
81+
const instanceStarts = instances.map(
82+
(instance) => instance.start?.dateTime,
83+
);
84+
85+
expect(instances).toHaveLength(3);
86+
expect(new Set(instanceStarts).size).toBe(3);
87+
});
88+
6489
describe("diffOptions", () => {
6590
it("should return the differences between two rrule options", () => {
6691
const until = dayjs();

packages/backend/src/event/classes/gcal.event.rrule.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,21 @@ export class GcalEventRRule extends RRule {
8181
const includesDtStart = this.#startDate.isSame(firstInstanceStartDate);
8282
const rDates = includesDtStart ? [] : [this.#startDate.toDate()];
8383

84-
return rDates.concat(dates);
84+
const uniqueDates = this.deduplicateByDate(rDates.concat(dates));
85+
return uniqueDates;
86+
}
87+
88+
deduplicateByDate(dates: Date[]): Date[] {
89+
const seen = new Set<string>();
90+
91+
return dates.filter((date) => {
92+
const key = dayjs(date).tz(this.#timezone).format(this.#dateFormat);
93+
94+
if (seen.has(key)) return false;
95+
96+
seen.add(key);
97+
return true;
98+
});
8599
}
86100

87101
/**

packages/scripts/src/commands/build.backend.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,25 @@
77
*
88
* Usage:
99
* bun run build:backend
10-
* bun run build:backend --environment staging
11-
* bun run build:backend --environment production
1210
*/
1311

1412
import {
1513
COMPASS_BUILD_DEV,
1614
COMPASS_ROOT_DEV,
1715
} from "@scripts/common/cli.constants";
18-
import { getEnvironmentAnswer, log } from "@scripts/common/cli.utils";
1916
import { $ } from "bun";
2017
import path from "node:path";
18+
import { styleText } from "node:util";
2119

2220
const BACKEND_BUILD = path.join(COMPASS_BUILD_DEV, "backend");
2321

24-
// Parse --environment flag; prompt if absent
25-
const envFlagIdx = process.argv.indexOf("--environment");
26-
let environment: string =
27-
envFlagIdx !== -1 ? (process.argv[envFlagIdx + 1] ?? "") : "";
28-
29-
const validEnvs = ["local", "staging", "production"];
30-
if (!validEnvs.includes(environment)) {
31-
environment = await getEnvironmentAnswer();
32-
}
22+
const log = {
23+
info: (msg: string) => console.log(styleText(["italic", "whiteBright"], msg)),
24+
error: (msg: string) => console.log(styleText(["bold", "red"], msg)),
25+
warning: (msg: string) => console.log(styleText("yellow", msg)),
26+
success: (msg: string) => console.log(styleText("green", msg)),
27+
tip: (msg: string) => console.log(styleText("yellowBright", msg)),
28+
};
3329

3430
// 1. Clean old build
3531
log.info("Removing old backend build ...");

self-host/Dockerfile.backend

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ WORKDIR /app
44
COPY . .
55

66
RUN bun install --frozen-lockfile
7-
RUN bun run build:backend --environment local
7+
RUN bun run build:backend
88

99
FROM oven/bun:1.2.18-slim AS runtime
1010

self-host/docker-compose.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ function readRepoFile(path: string): string {
99
}
1010

1111
describe("self-host docker compose", () => {
12+
it("builds the backend image without build-time Compass config", () => {
13+
const dockerfile = readRepoFile("self-host/Dockerfile.backend");
14+
15+
expect(dockerfile).toContain("RUN bun run build:backend");
16+
expect(dockerfile).not.toContain("--environment");
17+
});
18+
1219
it("mounts compass.yaml into the backend container", () => {
1320
const compose = readFileSync(join(import.meta.dir, "compose.yaml"), {
1421
encoding: "utf8",

0 commit comments

Comments
 (0)