Skip to content

Commit

Permalink
feat(cli): dockerize (#6858)
Browse files Browse the repository at this point in the history
* import dockerfile from old cli

* build works

* rename login command

* bump packages

* fix login command

* chore: remove axios dependency from CLI

* move immich script path

* can build docker

* wip

* wip

* don't externalize sdk

* can run docker

* improve entrypoint

* can save auth state between runs

* add docs

* clarify reqs

* fix lint

* bump alpine to 3.19

* add env files for api key

* remove immich cli GHA for now

* Update docs/docs/features/command-line-interface.md

Co-authored-by: Ben McCann <322311+benmccann@users.noreply.github.com>

* remove redundant env variable check

* cleanup

* speling

---------

Co-authored-by: Ben McCann <322311+benmccann@users.noreply.github.com>
  • Loading branch information
etnoy and benmccann authored Feb 6, 2024
1 parent 9b3764d commit 31eb479
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 31 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
platforms: linux/amd64
device: openvino
suffix: -openvino

- image: immich-machine-learning
context: machine-learning
file: machine-learning/Dockerfile
Expand All @@ -57,6 +57,7 @@ jobs:
file: server/Dockerfile
platforms: linux/amd64,linux/arm64
device: cpu

steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down
22 changes: 11 additions & 11 deletions cli/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
FROM ghcr.io/immich-app/base-server-dev:20240130@sha256:a11ac5c56f0ccce1f218954c07c43caadf489557252ba5b9ca1c5977aaa25999 as test
FROM node:20-alpine3.19 as core

WORKDIR /usr/src/app/server
COPY server/package.json server/package-lock.json ./
WORKDIR /usr/src/open-api/typescript-sdk
COPY open-api/typescript-sdk/package*.json open-api/typescript-sdk/tsconfig*.json ./
RUN npm ci
COPY ./server/ .
COPY open-api/typescript-sdk/ ./
RUN npm run build

WORKDIR /usr/src/app

WORKDIR /usr/src/app/cli
COPY cli/package.json cli/package-lock.json ./
RUN npm ci
COPY ./cli/ .

FROM ghcr.io/immich-app/base-server-prod:20240130@sha256:ce23a32154540b906df3c971766bcd991561c60331794e0ebb780947ac48113f

VOLUME /usr/src/app/upload
COPY cli .
RUN npm run build

EXPOSE 3001
WORKDIR /import

ENTRYPOINT ["tini", "--", "/bin/sh"]
ENTRYPOINT ["node", "/usr/src/app/dist"]
18 changes: 9 additions & 9 deletions cli/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"type": "module",
"exports": "./dist/index.js",
"bin": {
"immich": "./dist/src/index.js"
"immich": "./dist/index.js"
},
"license": "MIT",
"keywords": [
Expand All @@ -24,7 +24,7 @@
"@vitest/coverage-v8": "^1.2.2",
"byte-size": "^8.1.1",
"cli-progress": "^3.12.0",
"commander": "^11.0.0",
"commander": "^12.0.0",
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.1.3",
Expand Down
File renamed without changes.
11 changes: 7 additions & 4 deletions cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,22 @@ import { Command, Option } from 'commander';
import path from 'node:path';
import os from 'node:os';
import { version } from '../package.json';
import { LoginCommand } from './commands/login';
import { LoginCommand } from './commands/login.command';
import { LogoutCommand } from './commands/logout.command';
import { ServerInfoCommand } from './commands/server-info.command';
import { UploadCommand } from './commands/upload.command';

const homeDirectory = os.homedir();
const configDirectory = path.join(homeDirectory, '.config/immich/');
const defaultConfigDirectory = path.join(os.homedir(), '.config/immich/');

const program = new Command()
.name('immich')
.version(version)
.description('Command line interface for Immich')
.addOption(new Option('-d, --config', 'Configuration directory').env('IMMICH_CONFIG_DIR').default(configDirectory));
.addOption(
new Option('-d, --config-directory', 'Configuration directory where auth.yml will be stored')
.env('IMMICH_CONFIG_DIR')
.default(defaultConfigDirectory),
);

program
.command('upload')
Expand Down
3 changes: 1 addition & 2 deletions cli/test/e2e/login-key.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { restoreTempFolder, testApp } from '@test-utils';
import { CLI_BASE_OPTIONS, TEST_AUTH_FILE, deleteAuthFile, setup, spyOnConsole } from 'test/cli-test-utils';
import { readFile, stat } from 'node:fs/promises';
import { LoginCommand } from '../../src/commands/login';
import { LoginCommand } from '../../src/commands/login.command';
import yaml from 'yaml';

describe(`login-key (e2e)`, () => {
Expand Down Expand Up @@ -58,7 +58,6 @@ describe(`login-key (e2e)`, () => {
await new LoginCommand(CLI_BASE_OPTIONS).run(instanceUrl, apiKey);

const stats = await stat(TEST_AUTH_FILE);

const mode = (stats.mode & 0o777).toString(8);

expect(mode).toEqual('600');
Expand Down
16 changes: 14 additions & 2 deletions docs/docs/features/command-line-interface.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ If you are looking to import your Google Photos takeout, we recommend this commu

## Requirements

- Node.js 20.0 or above
- Node.js 20 or above
- Npm

## Installation
If you can't install node/npm, there is also a Docker version available below.

## Installation (NPM)

```bash
npm i -g @immich/cli
Expand All @@ -30,6 +32,16 @@ NOTE: if you previously installed the legacy CLI, you will need to uninstall it
npm uninstall -g immich
```

## Installation (Docker)

If npm is not available on your system you can try the Docker version

```bash
docker run -it -v "$(pwd)":/import:ro -e IMMICH_API_KEY=https://your-immich-instance/api -e IMMICH_API_KEY=your-api-key ghcr.io/immich-app/immich-cli:latest
```

Please modify the `IMMICH_INSTANCE_URL` and `IMMICH_API_KEY` environment variables as suitable. You can also use a Docker env file to store your sensitive API key.

## Usage

```
Expand Down

0 comments on commit 31eb479

Please sign in to comment.