Skip to content

Commit

Permalink
feat(cli): Use canary Docker image when using canary CLI client (#1316)
Browse files Browse the repository at this point in the history
This has been discussed but when using the canary version of the client
it's currently not clear that you should also manually set the
`ELECTRIC_IMAGE` to the canary tag as well - the proposed solution is to
make the CLI automatically detect that and use the appropriate image.

The `LIB_VERSION` generated by the changesets does not update for the
canary releases so I had to use the `package.json` directly, but since
this is for the CLI only (which we are also splitting out of the client)
that should be fine, it's not meant to be browser-runnable code.

This is mostly a quality of life improvement for us developing electric
as the current requirement to remember to point to canary releases for
both the sync service and client is slightly annoying.
  • Loading branch information
msfstef committed Jun 4, 2024
1 parent adffce3 commit 81d91f5
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/gold-poets-invent.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"electric-sql": patch
---

Use canary Docker image tag when using the canary CLI client.
16 changes: 11 additions & 5 deletions clients/typescript/src/cli/config-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@ import {
getConfigValue,
type ConfigMap,
} from './config'
import { dedent, getAppName, buildDatabaseURL, parsePgProxyPort } from './util'
import { LIB_VERSION } from '../version'

const minorVersion = LIB_VERSION.split('.').slice(0, 2).join('.')
import {
dedent,
getAppName,
buildDatabaseURL,
parsePgProxyPort,
LIB_MINOR_VERSION,
isCanaryRelease,
} from './util'

// Name will be prefixed with ELECTRIC_ as environment variables.
export const configOptions: Record<string, any> = {
Expand Down Expand Up @@ -312,7 +316,9 @@ export const configOptions: Record<string, any> = {
ELECTRIC_IMAGE: {
valueType: String,
valueTypeName: 'image',
defaultVal: `electricsql/electric:${minorVersion}`, // Latest minor version of this library
defaultVal: `electricsql/electric:${
isCanaryRelease() ? 'canary' : LIB_MINOR_VERSION
}`,
doc: 'The Docker image to use for Electric.',
groups: ['electric'],
},
Expand Down
1 change: 1 addition & 0 deletions clients/typescript/src/cli/util/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export * from './io'
export * from './parse'
export * from './string'
export * from './paths'
export * from './version'
35 changes: 35 additions & 0 deletions clients/typescript/src/cli/util/version.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import fs from 'fs'
import { LIB_VERSION } from '../../version'
import path from 'path'
import { fileURLToPath } from 'url'

/**
* Reads and parses the contents of the package.json of the CLI itself
*/
function readPackageJson(): Record<string, unknown> {
return JSON.parse(
fs.readFileSync(
path.join(
fileURLToPath(import.meta.url),
'..',
'..',
'..',
'..',
'package.json'
),
'utf8'
)
)
}

/**
* Check whether the CLI is a canary release.
*
* The LIB_VERSION export does not update for canary releases
* so this uses the package.json explicitly for this check
*/
export function isCanaryRelease(): boolean {
return (readPackageJson().version as string).includes('canary')
}

export const LIB_MINOR_VERSION = LIB_VERSION.split('.').slice(0, 2).join('.')

0 comments on commit 81d91f5

Please sign in to comment.