diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..04c01ba --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +node_modules/ +dist/ \ No newline at end of file diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..697c6fc --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,49 @@ +name: Create and publish a Docker image + +on: + push: + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + build-and-push-image: + runs-on: ubuntu-latest + # Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job. + permissions: + contents: read + packages: write + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Log in to the Container registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3.2.0 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: . + file: Dockerfile + push: true + platforms: linux/amd64,linux/arm64,linux/arm/v7 + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/.gitignore b/.gitignore index 9f38855..93a3f94 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ /node_modules/ +/dist/ /.idea/ .env /package-lock.json diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..a3935b2 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,12 @@ +FROM node:20-slim + +WORKDIR /app + +COPY package*.json ./ +RUN npm install --omit=dev + +COPY . . + +RUN npm run build + +CMD [ "node", "dist/index.js" ] diff --git a/dist/immich.js b/dist/immich.js deleted file mode 100644 index 5f0fbf8..0000000 --- a/dist/immich.js +++ /dev/null @@ -1,104 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -const tslib_1 = require("tslib"); -const types_1 = require("./types"); -const dayjs_1 = tslib_1.__importDefault(require("dayjs")); -const index_1 = require("./index"); -class Immich { - /** - * Make a request to Immich API. We're not using the SDK to limit - * the possible attack surface of this app. - */ - request(endpoint) { - return tslib_1.__awaiter(this, void 0, void 0, function* () { - const res = yield fetch(process.env.IMMICH_URL + '/api' + endpoint); - if (res.status === 200) { - const contentType = res.headers.get('Content-Type') || ''; - if (contentType.includes('application/json')) { - return res.json(); - } - else { - return res; - } - } - else { - (0, index_1.log)('Immich API status ' + res.status); - console.log(yield res.text()); - } - }); - } - /** - * Query Immich for the SharedLink metadata for a given key. - * The key is what is returned in the URL when you create a share in Immich. - */ - getShareByKey(key) { - return tslib_1.__awaiter(this, void 0, void 0, function* () { - const link = (yield this.request('/shared-links/me?key=' + encodeURIComponent(key))); - if (link) { - if (link.expiresAt && (0, dayjs_1.default)(link.expiresAt) < (0, dayjs_1.default)()) { - // This link has expired - (0, index_1.log)('Expired link ' + key); - } - else { - // Filter assets to exclude trashed assets - link.assets = link.assets.filter(asset => !asset.isTrashed); - link.assets.forEach(asset => { asset.key = key; }); - return link; - } - } - }); - } - /** - * Stream asset buffer data from Immich. - * - * For photos, you can request 'thumbnail' or 'original' size. - * For videos, it is Immich's streaming quality, not the original quality. - */ - getAssetBuffer(asset, size) { - return tslib_1.__awaiter(this, void 0, void 0, function* () { - switch (asset.type) { - case types_1.AssetType.image: - size = size === types_1.ImageSize.thumbnail ? types_1.ImageSize.thumbnail : types_1.ImageSize.original; - return this.request('/assets/' + encodeURIComponent(asset.id) + '/' + size + '?key=' + encodeURIComponent(asset.key)); - case types_1.AssetType.video: - return this.request('/assets/' + encodeURIComponent(asset.id) + '/video/playback?key=' + encodeURIComponent(asset.key)); - } - }); - } - /** - * Get the content-type of an Immich asset - */ - getContentType(asset) { - return tslib_1.__awaiter(this, void 0, void 0, function* () { - const assetBuffer = yield this.getAssetBuffer(asset); - return assetBuffer.headers.get('Content-Type'); - }); - } - /** - * Return the image data URL for a photo - */ - photoUrl(key, id, size) { - return `/photo/${key}/${id}` + (size ? `?size=${size}` : ''); - } - /** - * Return the video data URL for a video - */ - videoUrl(key, id) { - return `/video/${key}/${id}`; - } - /** - * Check if a provided ID matches the Immich ID format - */ - isId(id) { - return !!id.match(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/); - } - /** - * Check if a provided key matches the Immich shared-link key format - */ - isKey(key) { - return !!key.match(/^[\w-]+$/); - } -} -const immich = new Immich(); -exports.default = immich; -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW1taWNoLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vc3JjL2ltbWljaC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7QUFBQSxtQ0FBd0U7QUFDeEUsMERBQXlCO0FBQ3pCLG1DQUE2QjtBQUU3QixNQUFNLE1BQU07SUFDVjs7O09BR0c7SUFDRyxPQUFPLENBQUUsUUFBZ0I7O1lBQzdCLE1BQU0sR0FBRyxHQUFHLE1BQU0sS0FBSyxDQUFDLE9BQU8sQ0FBQyxHQUFHLENBQUMsVUFBVSxHQUFHLE1BQU0sR0FBRyxRQUFRLENBQUMsQ0FBQTtZQUNuRSxJQUFJLEdBQUcsQ0FBQyxNQUFNLEtBQUssR0FBRyxFQUFFLENBQUM7Z0JBQ3ZCLE1BQU0sV0FBVyxHQUFHLEdBQUcsQ0FBQyxPQUFPLENBQUMsR0FBRyxDQUFDLGNBQWMsQ0FBQyxJQUFJLEVBQUUsQ0FBQTtnQkFDekQsSUFBSSxXQUFXLENBQUMsUUFBUSxDQUFDLGtCQUFrQixDQUFDLEVBQUUsQ0FBQztvQkFDN0MsT0FBTyxHQUFHLENBQUMsSUFBSSxFQUFFLENBQUE7Z0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DaGVjayBpZiBhIHByb3ZpZGVkIElEIG1hdGNoZXMgdGhlIEltbWljaCBJRCBmb3JtYXRcbiAgICovXG4gIGlzSWQgKGlkOiBzdHJpbmcpIHtcbiAgICByZXR1cm4gISFpZC5tYXRjaCgvXlswLTlhLWZdezh9LVswLTlhLWZdezR9LVswLTlhLWZdezR9LVswLTlhLWZdezR9LVswLTlhLWZdezEyfSQvKVxuICB9XG5cbiAgLyoqXG4gICAqIENoZWNrIGlmIGEgcHJvdmlkZWQga2V5IG1hdGNoZXMgdGhlIEltbWljaCBzaGFyZWQtbGluayBrZXkgZm9ybWF0XG4gICAqL1xuICBpc0tleSAoa2V5OiBzdHJpbmcpIHtcbiAgICByZXR1cm4gISFrZXkubWF0Y2goL15bXFx3LV0rJC8pXG4gIH1cbn1cblxuY29uc3QgaW1taWNoID0gbmV3IEltbWljaCgpXG5cbmV4cG9ydCBkZWZhdWx0IGltbWljaFxuIl19 \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index b6c09e5..0000000 --- a/dist/index.js +++ /dev/null @@ -1,94 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.log = void 0; -const tslib_1 = require("tslib"); -const express_1 = tslib_1.__importDefault(require("express")); -const immich_1 = tslib_1.__importDefault(require("./immich")); -const render_1 = tslib_1.__importDefault(require("./render")); -const dayjs_1 = tslib_1.__importDefault(require("dayjs")); -const types_1 = require("./types"); -require('dotenv').config(); -const app = (0, express_1.default)(); -// Add the EJS view engine, to render the gallery page -app.set('view engine', 'ejs'); -// Serve static assets from the /public folder -app.use(express_1.default.static('public')); -// An incoming request for a shared link -app.get('/share/:key', (req, res) => tslib_1.__awaiter(void 0, void 0, void 0, function* () { - res.set('Cache-Control', 'public, max-age=' + process.env.CACHE_AGE); - if (!immich_1.default.isKey(req.params.key)) { - (0, exports.log)('Invalid share key ' + req.params.key); - res.status(404).send(); - } - else { - const sharedLink = yield immich_1.default.getShareByKey(req.params.key); - if (!sharedLink) { - (0, exports.log)('Unknown share key ' + req.params.key); - res.status(404).send(); - } - else if (!sharedLink.assets.length) { - (0, exports.log)('No assets for key ' + req.params.key); - res.status(404).send(); - } - else if (sharedLink.assets.length === 1) { - // This is an individual item (not a gallery) - (0, exports.log)('Serving link ' + req.params.key); - const asset = sharedLink.assets[0]; - if (asset.type === types_1.AssetType.image) { - // For photos, output the image directly - yield render_1.default.assetBuffer(res, sharedLink.assets[0], getSize(req)); - } - else if (asset.type === types_1.AssetType.video) { - // For videos, show the video as a web player - yield render_1.default.gallery(res, sharedLink, 1); - } - } - else { - // Multiple images - render as a gallery - (0, exports.log)('Serving link ' + req.params.key); - yield render_1.default.gallery(res, sharedLink); - } - } -})); -// Output the buffer data for a photo or video -app.get('/:type(photo|video)/:key/:id', (req, res) => tslib_1.__awaiter(void 0, void 0, void 0, function* () { - res.set('Cache-Control', 'public, max-age=' + process.env.CACHE_AGE); - // Check for valid key and ID - if (immich_1.default.isKey(req.params.key) && immich_1.default.isId(req.params.id)) { - // Check if the key is a valid share link - const sharedLink = yield immich_1.default.getShareByKey(req.params.key); - if (sharedLink === null || sharedLink === void 0 ? void 0 : sharedLink.assets.length) { - // Check that the requested asset exists in this share - const asset = sharedLink.assets.find(x => x.id === req.params.id); - if (asset) { - asset.type = req.params.type === 'video' ? types_1.AssetType.video : types_1.AssetType.image; - render_1.default.assetBuffer(res, asset, getSize(req)).then(); - return; - } - } - } - (0, exports.log)('No asset found for ' + req.path); - res.status(404).send(); -})); -// Send a 404 for all other routes -app.get('*', (req, res) => { - (0, exports.log)('Invalid route ' + req.path); - res.status(404).send(); -}); -/** - * Sanitise the data for an incoming query string `size` parameter - * e.g. https://example.com/share/abc...xyz?size=thumbnail - */ -const getSize = (req) => { - var _a; - return ((_a = req === null || req === void 0 ? void 0 : req.query) === null || _a === void 0 ? void 0 : _a.size) === 'thumbnail' ? types_1.ImageSize.thumbnail : types_1.ImageSize.original; -}; -/** - * Output a console.log message with timestamp - */ -const log = (message) => console.log((0, dayjs_1.default)().format() + ' ' + message); -exports.log = log; -app.listen(3000, () => { - console.log((0, dayjs_1.default)().format() + ' Server started'); -}); -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7OztBQUFBLDhEQUE2QjtBQUM3Qiw4REFBNkI7QUFDN0IsOERBQTZCO0FBQzdCLDBEQUF5QjtBQUN6QixtQ0FBOEM7QUFHOUMsT0FBTyxDQUFDLFFBQVEsQ0FBQyxDQUFDLE1BQU0sRUFBRSxDQUFBO0FBRTFCLE1BQU0sR0FBRyxHQUFHLElBQUEsaUJBQU8sR0FBRSxDQUFBO0FBQ3JCLHNEQUFzRDtBQUN0RCxHQUFHLENBQUMsR0FBRyxDQUFDLGFBQWEsRUFBRSxLQUFLLENBQUMsQ0FBQTtBQUM3Qiw4Q0FBOEM7QUFDOUMsR0FBRyxDQUFDLEdBQUcsQ0FBQyxpQkFBTyxDQUFDLE1BQU0sQ0FBQyxRQUFRLENBQUMsQ0FBQyxDQUFBO0FBRWpDLHdDQUF3QztBQUN4QyxHQUFHLENBQUMsR0FBRyxDQUFDLGFBQWEsRUFBRSxDQUFPLEdBQUcsRUFBRSxHQUFHLEVBQUUsRUFBRTtJQUN4QyxHQUFHLENBQUMsR0FBRyxDQUFDLGVBQWUsRUFBRSxrQkFBa0IsR0FBRyxPQUFPLENBQUMsR0FBRyxDQUFDLFNBQVMsQ0FBQyxDQUFBO0lBQ3BFLElBQUksQ0FBQyxnQkFBTSxDQUFDLEtBQUssQ0FBQyxHQUFHLENBQUMsTUFBTSxDQUFDLEdBQUcsQ0FBQyxFQUFFLENBQUM7UUFDbEMsSUFBQSxXQUFHLEVBQUMsb0JBQW9CLEdBQUcsR0FBRyxDQUFDLE1BQU0sQ0FBQyxHQUFHLENBQUMs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dGF0dXMoNDA0KS5zZW5kKClcbn0pXG5cbi8vIFNlbmQgYSA0MDQgZm9yIGFsbCBvdGhlciByb3V0ZXNcbmFwcC5nZXQoJyonLCAocmVxLCByZXMpID0+IHtcbiAgbG9nKCdJbnZhbGlkIHJvdXRlICcgKyByZXEucGF0aClcbiAgcmVzLnN0YXR1cyg0MDQpLnNlbmQoKVxufSlcblxuLyoqXG4gKiBTYW5pdGlzZSB0aGUgZGF0YSBmb3IgYW4gaW5jb21pbmcgcXVlcnkgc3RyaW5nIGBzaXplYCBwYXJhbWV0ZXJcbiAqIGUuZy4gaHR0cHM6Ly9leGFtcGxlLmNvbS9zaGFyZS9hYmMuLi54eXo/c2l6ZT10aHVtYm5haWxcbiAqL1xuY29uc3QgZ2V0U2l6ZSA9IChyZXE6IFJlcXVlc3QpID0+IHtcbiAgcmV0dXJuIHJlcT8ucXVlcnk/LnNpemUgPT09ICd0aHVtYm5haWwnID8gSW1hZ2VTaXplLnRodW1ibmFpbCA6IEltYWdlU2l6ZS5vcmlnaW5hbFxufVxuXG4vKipcbiAqIE91dHB1dCBhIGNvbnNvbGUubG9nIG1lc3NhZ2Ugd2l0aCB0aW1lc3RhbXBcbiAqL1xuZXhwb3J0IGNvbnN0IGxvZyA9IChtZXNzYWdlOiBzdHJpbmcpID0+IGNvbnNvbGUubG9nKGRheWpzKCkuZm9ybWF0KCkgKyAnICcgKyBtZXNzYWdlKVxuXG5hcHAubGlzdGVuKDMwMDAsICgpID0+IHtcbiAgY29uc29sZS5sb2coZGF5anMoKS5mb3JtYXQoKSArICcgU2VydmVyIHN0YXJ0ZWQnKVxufSlcbiJdfQ== \ No newline at end of file diff --git a/dist/render.js b/dist/render.js deleted file mode 100644 index 28e9374..0000000 --- a/dist/render.js +++ /dev/null @@ -1,63 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -const tslib_1 = require("tslib"); -const immich_1 = tslib_1.__importDefault(require("./immich")); -const types_1 = require("./types"); -class Render { - assetBuffer(res, asset, size) { - return tslib_1.__awaiter(this, void 0, void 0, function* () { - const data = yield immich_1.default.getAssetBuffer(asset, size); - if (data) { - for (const header of ['content-type', 'content-length']) { - res.set(header, data.headers[header]); - } - res.send(Buffer.from(yield data.arrayBuffer())); - } - else { - res.status(404).send(); - } - }); - } - /** - * Render a gallery page for a given SharedLink, using EJS and lightGallery. - * - * @param res - ExpressJS Response - * @param share - Immich `shared-link` containing the assets to show in the gallery - * @param [openItem] - Immediately open a lightbox to the Nth item when the gallery loads - */ - gallery(res, share, openItem) { - return tslib_1.__awaiter(this, void 0, void 0, function* () { - const items = []; - for (const asset of share.assets) { - let video; - if (asset.type === types_1.AssetType.video) { - // Populate the data-video property - video = JSON.stringify({ - source: [ - { - src: immich_1.default.videoUrl(share.key, asset.id), - type: yield immich_1.default.getContentType(asset) - } - ], - attributes: { - preload: false, - controls: true - } - }); - } - items.push({ - originalUrl: immich_1.default.photoUrl(share.key, asset.id), - thumbnailUrl: immich_1.default.photoUrl(share.key, asset.id, types_1.ImageSize.thumbnail), - video - }); - } - res.render('gallery', { - items, - openItem - }); - }); - } -} -const render = new Render(); -exports.default = render; -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicmVuZGVyLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vc3JjL3JlbmRlci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7QUFBQSw4REFBNkI7QUFFN0IsbUNBQWlFO0FBRWpFLE1BQU0sTUFBTTtJQUNKLFdBQVcsQ0FBRSxHQUFhLEVBQUUsS0FBWSxFQUFFLElBQWdCOztZQUM5RCxNQUFNLElBQUksR0FBRyxNQUFNLGdCQUFNLENBQUMsY0FBYyxDQUFDLEtBQUssRUFBRSxJQUFJLENBQUMsQ0FBQTtZQUNyRCxJQUFJLElBQUksRUFBRSxDQUFDO2dCQUNULEtBQUssTUFBTSxNQUFNLElBQUksQ0FBQyxjQUFjLEV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09OLnN0cmluZ2lmeSh7XG4gICAgICAgICAgc291cmNlOiBbXG4gICAgICAgICAgICB7XG4gICAgICAgICAgICAgIHNyYzogaW1taWNoLnZpZGVvVXJsKHNoYXJlLmtleSwgYXNzZXQuaWQpLFxuICAgICAgICAgICAgICB0eXBlOiBhd2FpdCBpbW1pY2guZ2V0Q29udGVudFR5cGUoYXNzZXQpXG4gICAgICAgICAgICB9XG4gICAgICAgICAgXSxcbiAgICAgICAgICBhdHRyaWJ1dGVzOiB7XG4gICAgICAgICAgICBwcmVsb2FkOiBmYWxzZSxcbiAgICAgICAgICAgIGNvbnRyb2xzOiB0cnVlXG4gICAgICAgICAgfVxuICAgICAgICB9KVxuICAgICAgfVxuICAgICAgaXRlbXMucHVzaCh7XG4gICAgICAgIG9yaWdpbmFsVXJsOiBpbW1pY2gucGhvdG9Vcmwoc2hhcmUua2V5LCBhc3NldC5pZCksXG4gICAgICAgIHRodW1ibmFpbFVybDogaW1taWNoLnBob3RvVXJsKHNoYXJlLmtleSwgYXNzZXQuaWQsIEltYWdlU2l6ZS50aHVtYm5haWwpLFxuICAgICAgICB2aWRlb1xuICAgICAgfSlcbiAgICB9XG4gICAgcmVzLnJlbmRlcignZ2FsbGVyeScsIHtcbiAgICAgIGl0ZW1zLFxuICAgICAgb3Blbkl0ZW1cbiAgICB9KVxuICB9XG59XG5cbmNvbnN0IHJlbmRlciA9IG5ldyBSZW5kZXIoKVxuXG5leHBvcnQgZGVmYXVsdCByZW5kZXJcbiJdfQ== \ No newline at end of file diff --git a/dist/types.js b/dist/types.js deleted file mode 100644 index 90d21e7..0000000 --- a/dist/types.js +++ /dev/null @@ -1,14 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.ImageSize = exports.AssetType = void 0; -var AssetType; -(function (AssetType) { - AssetType["image"] = "IMAGE"; - AssetType["video"] = "VIDEO"; -})(AssetType || (exports.AssetType = AssetType = {})); -var ImageSize; -(function (ImageSize) { - ImageSize["thumbnail"] = "thumbnail"; - ImageSize["original"] = "original"; -})(ImageSize || (exports.ImageSize = ImageSize = {})); -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHlwZXMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvdHlwZXMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7O0FBQUEsSUFBWSxTQUdYO0FBSEQsV0FBWSxTQUFTO0lBQ25CLDRCQUFlLENBQUE7SUFDZiw0QkFBZSxDQUFBO0FBQ2pCLENBQUMsRUFIVyxTQUFTLHlCQUFULFNBQVMsUUFHcEI7QUF1QkQsSUFBWSxTQUdYO0FBSEQsV0FBWSxTQUFTO0lBQ25CLG9DQUF1QixDQUFBO0lBQ3ZCLGtDQUFxQixDQUFBO0FBQ3ZCLENBQUMsRUFIVyxTQUFTLHlCQUFULFNBQVMsUUFHcEIiLCJzb3VyY2VzQ29udGVudCI6WyJleHBvcnQgZW51bSBBc3NldFR5cGUge1xuICBpbWFnZSA9ICdJTUFHRScsXG4gIHZpZGVvID0gJ1ZJREVPJ1xufVxuXG5leHBvcnQgaW50ZXJmYWNlIEFzc2V0IHtcbiAgaWQ6IHN0cmluZztcbiAga2V5OiBzdHJpbmc7XG4gIHR5cGU6IEFzc2V0VHlwZTtcbiAgaXNUcmFzaGVkOiBib29sZWFuO1xufVxuXG5leHBvcnQgaW50ZXJmYWNlIFNoYXJlZExpbmsge1xuICBrZXk6IHN0cmluZztcbiAgdHlwZTogc3RyaW5nO1xuICBhc3NldHM6IEFzc2V0W107XG4gIGFsYnVtPzoge1xuICAgIGlkOiBzdHJpbmc7XG4gIH1cbiAgZXhwaXJlc0F0OiBzdHJpbmcgfCBudWxsO1xufVxuXG5leHBvcnQgaW50ZXJmYWNlIEFsYnVtIHtcbiAgYXNzZXRzOiBBc3NldFtdXG59XG5cbmV4cG9ydCBlbnVtIEltYWdlU2l6ZSB7XG4gIHRodW1ibmFpbCA9ICd0aHVtYm5haWwnLFxuICBvcmlnaW5hbCA9ICdvcmlnaW5hbCdcbn1cbiJdfQ== \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index cebae78..96a9eb3 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,19 +1,13 @@ -version: "3" - services: - public-proxy: - image: "node:22" + immich-public-proxy: + image: ghcr.io/alangrainger/immich-public-proxy:latest container_name: immich-public-proxy - working_dir: /home/node/app - environment: - - NODE_ENV=production - volumes: - - ./:/home/node/app:Z + restart: unless-stopped ports: - ${PORT}:3000 - command: bash -c "cd /home/node/app && npm install && npm start" - restart: always - healthcheck: - test: (ps ax | grep -q "[n]ode dist/index.js" && echo "Ok") || exit 1 - interval: 60s - start_period: 10s + environment: + - NODE_ENV=production + env_file: + - .env + +