From 94b0e643b460a45e278b65ca0670dfb6b70d4656 Mon Sep 17 00:00:00 2001 From: Tarow Date: Wed, 30 Oct 2024 16:24:34 +0000 Subject: [PATCH 1/4] feat(ci): add docker build&publish pipeline --- .dockerignore | 2 + .github/workflows/ci.yaml | 50 ++++++++++++++++++ .gitignore | 1 + Dockerfile | 12 +++++ dist/immich.js | 107 -------------------------------------- dist/index.js | 92 -------------------------------- dist/render.js | 63 ---------------------- dist/types.js | 14 ----- 8 files changed, 65 insertions(+), 276 deletions(-) create mode 100644 .dockerignore create mode 100644 .github/workflows/ci.yaml create mode 100644 Dockerfile delete mode 100644 dist/immich.js delete mode 100644 dist/index.js delete mode 100644 dist/render.js delete mode 100644 dist/types.js 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..d641a36 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,50 @@ +name: Create and publish a Docker image + +on: + push: + branches: + - "**" + tags: + - "**" + +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 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 75b0373..19bb801 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /node_modules/ +/dist/ /.idea/ .env 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 0a77462..0000000 --- a/dist/immich.js +++ /dev/null @@ -1,107 +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, { - headers: { - 'x-api-key': process.env.API_KEY || '' - } - }); - if (res.status === 200) { - const contentType = res.headers.get('Content-Type') || ''; - if (contentType.includes('application/json')) { - return res.json(); - } - else { - return res; - } - } - }); - } - /** - * 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. - * - * Immich doesn't have a method to query by key, so this method gets all - * known shared links, and returns the link which matches the provided key. - */ - getShareByKey(key) { - return tslib_1.__awaiter(this, void 0, void 0, function* () { - const res = ((yield this.request('/shared-links')) || []); - const link = res.find(x => x.key === key); - if (link) { - // Filter assets to exclude trashed assets - link.assets = link.assets.filter(x => !x.isTrashed); - 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 { - 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); - case types_1.AssetType.video: - return this.request('/assets/' + encodeURIComponent(asset.id) + '/video/playback'); - } - }); - } - /** - * 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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW1taWNoLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vc3JjL2ltbWljaC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7QUFBQSxtQ0FBaUU7QUFDakUsMERBQXlCO0FBQ3pCLG1DQUE2QjtBQUU3QixNQUFNLE1BQU07SUFDVjs7O09BR0c7SUFDRyxPQUFPLENBQUUsUUFBZ0I7O1lBQzdCLE1BQU0sR0FBRyxHQUFHLE1BQU0sS0FBSyxDQUFDLE9BQU8sQ0FBQyxHQUFHLENBQUMsVUFBVSxHQUFHLE1BQU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LCBpZDogc3RyaW5nKSB7XG4gICAgcmV0dXJuIGAvdmlkZW8vJHtrZXl9LyR7aWR9YFxuICB9XG5cbiAgLyoqXG4gICAqIENoZWNrIGlmIGEgcHJvdmlkZWQgSUQgbWF0Y2hlcyB0aGUgSW1taWNoIElEIGZvcm1hdFxuICAgKi9cbiAgaXNJZCAoaWQ6IHN0cmluZykge1xuICAgIHJldHVybiAhIWlkLm1hdGNoKC9eWzAtOWEtZl17OH0tWzAtOWEtZl17NH0tWzAtOWEtZl17NH0tWzAtOWEtZl17NH0tWzAtOWEtZl17MTJ9JC8pXG4gIH1cblxuICAvKipcbiAgICogQ2hlY2sgaWYgYSBwcm92aWRlZCBrZXkgbWF0Y2hlcyB0aGUgSW1taWNoIHNoYXJlZC1saW5rIGtleSBmb3JtYXRcbiAgICovXG4gIGlzS2V5IChrZXk6IHN0cmluZykge1xuICAgIHJldHVybiAhIWtleS5tYXRjaCgvXltcXHctXSskLylcbiAgfVxufVxuXG5jb25zdCBpbW1pY2ggPSBuZXcgSW1taWNoKClcblxuZXhwb3J0IGRlZmF1bHQgaW1taWNoXG4iXX0= \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 43d08be..0000000 --- a/dist/index.js +++ /dev/null @@ -1,92 +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)(); -app.set('view engine', 'ejs'); -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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7OztBQUFBLDhEQUE2QjtBQUM3Qiw4REFBNkI7QUFDN0IsOERBQTZCO0FBQzdCLDBEQUF5QjtBQUN6QixtQ0FBOEM7QUFHOUMsT0FBTyxDQUFDLFFBQVEsQ0FBQyxDQUFDLE1BQU0sRUFBRSxDQUFBO0FBRTFCLE1BQU0sR0FBRyxHQUFHLElBQUEsaUJBQU8sR0FBRSxDQUFBO0FBQ3JCLEdBQUcsQ0FBQyxHQUFHLENBQUMsYUFBYSxFQUFFLEtBQUssQ0FBQyxDQUFBO0FBQzdCLEdBQUcsQ0FBQyxHQUFHLENBQUMsaUJBQU8sQ0FBQyxNQUFNLENBQUMsUUFBUSxDQUFDLENBQUMsQ0FBQTtBQUVqQyx3Q0FBd0M7QUFDeEMsR0FBRyxDQUFDLEdBQUcsQ0FBQyxhQUFhLEVBQUUsQ0FBTyxHQUFHLEVBQUUsR0FBRyxFQUFFLEVBQUU7SUFDeEMsR0FBRyxDQUFDLEdBQUcsQ0FBQyxlQUFlLEVBQUUsa0JBQWtCLEdBQUcsT0FBTyxDQUFDLEdBQUcsQ0FBQyxTQUFTLENBQUMsQ0FBQTtJQUNwRSxJQUFJLENBQUMsZ0JBQU0sQ0FBQyxLQUFLLENBQUMsR0FBRyxDQUFDLE1BQU0sQ0FBQyxHQUFHLENBQUMsRUFBRSxDQUFDO1FBQ2xDLElBQUEsV0FBRyxFQUFDLG9CQUFvQixHQUFHLEdBQUcsQ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KicsIChyZXEsIHJlcykgPT4ge1xuICBsb2coJ0ludmFsaWQgcm91dGUgJyArIHJlcS5wYXRoKVxuICByZXMuc3RhdHVzKDQwNCkuc2VuZCgpXG59KVxuXG4vKipcbiAqIFNhbml0aXNlIHRoZSBkYXRhIGZvciBhbiBpbmNvbWluZyBxdWVyeSBzdHJpbmcgYHNpemVgIHBhcmFtZXRlclxuICogZS5nLiBodHRwczovL2V4YW1wbGUuY29tL3NoYXJlL2FiYy4uLnh5ej9zaXplPXRodW1ibmFpbFxuICovXG5jb25zdCBnZXRTaXplID0gKHJlcTogUmVxdWVzdCkgPT4ge1xuICByZXR1cm4gcmVxPy5xdWVyeT8uc2l6ZSA9PT0gJ3RodW1ibmFpbCcgPyBJbWFnZVNpemUudGh1bWJuYWlsIDogSW1hZ2VTaXplLm9yaWdpbmFsXG59XG5cbi8qKlxuICogT3V0cHV0IGEgY29uc29sZS5sb2cgbWVzc2FnZSB3aXRoIHRpbWVzdGFtcFxuICovXG5leHBvcnQgY29uc3QgbG9nID0gKG1lc3NhZ2U6IHN0cmluZykgPT4gY29uc29sZS5sb2coZGF5anMoKS5mb3JtYXQoKSArICcgJyArIG1lc3NhZ2UpXG5cbmFwcC5saXN0ZW4oMzAwMCwgKCkgPT4ge1xuICBjb25zb2xlLmxvZyhkYXlqcygpLmZvcm1hdCgpICsgJyBTZXJ2ZXIgc3RhcnRlZCcpXG59KVxuIl19 \ 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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicmVuZGVyLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vc3JjL3JlbmRlci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7QUFBQSw4REFBNkI7QUFFN0IsbUNBQWlFO0FBRWpFLE1BQU0sTUFBTTtJQUNKLFdBQVcsQ0FBRSxHQUFhLEVBQUUsS0FBWSxFQUFFLElBQWdCOztZQUM5RCxNQUFNLElBQUksR0FBRyxNQUFNLGdCQUFNLENBQUMsY0FBYyxDQUFDLEtBQUssRUFBRSxJQUFJLENBQUMsQ0FBQTtZQUNyRCxJQUFJLElBQUksRUFBRSxDQUFDO2dCQUNULEtBQUssTUFBTSxNQUFNLElBQUksQ0FBQyxjQUFjLEVBQUUsZ0JBQWdCLENBQUMsRUFBRSxDQUFDO29CQUN4RCxHQUFHLENBQUMsR0FBRyxDQUFDLE1BQU0sRUFBRSxJQUFJLENBQUMsT0FBTyxDQUFDLE1BQU0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gYXNzZXQuaWQpLFxuICAgICAgICAgICAgICB0eXBlOiBhd2FpdCBpbW1pY2guZ2V0Q29udGVudFR5cGUoYXNzZXQpXG4gICAgICAgICAgICB9XG4gICAgICAgICAgXSxcbiAgICAgICAgICBhdHRyaWJ1dGVzOiB7XG4gICAgICAgICAgICBwcmVsb2FkOiBmYWxzZSxcbiAgICAgICAgICAgIGNvbnRyb2xzOiB0cnVlXG4gICAgICAgICAgfVxuICAgICAgICB9KVxuICAgICAgfVxuICAgICAgaXRlbXMucHVzaCh7XG4gICAgICAgIG9yaWdpbmFsVXJsOiBpbW1pY2gucGhvdG9Vcmwoc2hhcmUua2V5LCBhc3NldC5pZCksXG4gICAgICAgIHRodW1ibmFpbFVybDogaW1taWNoLnBob3RvVXJsKHNoYXJlLmtleSwgYXNzZXQuaWQsIEltYWdlU2l6ZS50aHVtYm5haWwpLFxuICAgICAgICB2aWRlb1xuICAgICAgfSlcbiAgICB9XG4gICAgcmVzLnJlbmRlcignZ2FsbGVyeScsIHtcbiAgICAgIGl0ZW1zLFxuICAgICAgb3Blbkl0ZW1cbiAgICB9KVxuICB9XG59XG5cbmNvbnN0IHJlbmRlciA9IG5ldyBSZW5kZXIoKVxuXG5leHBvcnQgZGVmYXVsdCByZW5kZXJcbiJdfQ== \ No newline at end of file diff --git a/dist/types.js b/dist/types.js deleted file mode 100644 index a14bfb7..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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHlwZXMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvdHlwZXMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7O0FBQUEsSUFBWSxTQUdYO0FBSEQsV0FBWSxTQUFTO0lBQ25CLDRCQUFlLENBQUE7SUFDZiw0QkFBZSxDQUFBO0FBQ2pCLENBQUMsRUFIVyxTQUFTLHlCQUFULFNBQVMsUUFHcEI7QUFjRCxJQUFZLFNBR1g7QUFIRCxXQUFZLFNBQVM7SUFDbkIsb0NBQXVCLENBQUE7SUFDdkIsa0NBQXFCLENBQUE7QUFDdkIsQ0FBQyxFQUhXLFNBQVMseUJBQVQsU0FBUyxRQUdwQiIsInNvdXJjZXNDb250ZW50IjpbImV4cG9ydCBlbnVtIEFzc2V0VHlwZSB7XG4gIGltYWdlID0gJ0lNQUdFJyxcbiAgdmlkZW8gPSAnVklERU8nXG59XG5cbmV4cG9ydCBpbnRlcmZhY2UgQXNzZXQge1xuICBpZDogc3RyaW5nO1xuICB0eXBlOiBBc3NldFR5cGU7XG4gIGlzVHJhc2hlZDogYm9vbGVhbjtcbn1cblxuZXhwb3J0IGludGVyZmFjZSBTaGFyZWRMaW5rIHtcbiAga2V5OiBzdHJpbmc7XG4gIGFzc2V0czogQXNzZXRbXTtcbiAgZXhwaXJlc0F0OiBzdHJpbmcgfCBudWxsO1xufVxuXG5leHBvcnQgZW51bSBJbWFnZVNpemUge1xuICB0aHVtYm5haWwgPSAndGh1bWJuYWlsJyxcbiAgb3JpZ2luYWwgPSAnb3JpZ2luYWwnXG59XG4iXX0= \ No newline at end of file From 43e359a66efd7e22c481570c746324dfd1144cbe Mon Sep 17 00:00:00 2001 From: Tarow Date: Wed, 30 Oct 2024 18:53:04 +0100 Subject: [PATCH 2/4] Update .github/workflows/ci.yaml Co-authored-by: bo0tzz --- .github/workflows/ci.yaml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index d641a36..a34895b 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -2,10 +2,6 @@ name: Create and publish a Docker image on: push: - branches: - - "**" - tags: - - "**" env: REGISTRY: ghcr.io From 64cd1ab635e057bc64ff1f14f365c14068547929 Mon Sep 17 00:00:00 2001 From: "niklastasler@gmail.com" Date: Wed, 30 Oct 2024 19:20:47 +0100 Subject: [PATCH 3/4] refactor: docker-compose file to use registry image --- docker-compose.yml | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) 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 + + From 22592a94182a560b4f88d9be3cce9cbbe89de565 Mon Sep 17 00:00:00 2001 From: Tarow Date: Thu, 31 Oct 2024 08:10:10 +0100 Subject: [PATCH 4/4] Update .github/workflows/ci.yaml Co-authored-by: bo0tzz --- .github/workflows/ci.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index a34895b..697c6fc 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -26,6 +26,9 @@ jobs: 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