Browse Source

build(server): use github-action cache (#949)

* build(server): prune dependencies in docker builder

* fix: e2e tests

* refactor: dockerfile step order

* fix: vips build dependency

* feat: use caching
Jason Rasmussen 2 years ago
parent
commit
cc61729f01

+ 4 - 0
.github/workflows/build_push_docker_latest.yml

@@ -33,6 +33,8 @@ jobs:
           file: ./server/Dockerfile
           platforms: linux/arm/v7,linux/amd64,linux/arm64
           push: true
+          cache-from: type=gha
+          cache-to: type=gha,mode=max
           tags: |
             altran1502/immich-server:latest
 
@@ -61,6 +63,8 @@ jobs:
           file: ./machine-learning/Dockerfile
           platforms: linux/arm/v7,linux/amd64,linux/arm64
           push: true
+          cache-from: type=gha
+          cache-to: type=gha,mode=max
           tags: |
             altran1502/immich-machine-learning:latest
 

+ 4 - 0
.github/workflows/build_push_docker_staging.yml

@@ -34,6 +34,8 @@ jobs:
           file: ./server/Dockerfile
           platforms: linux/arm/v7,linux/amd64,linux/arm64
           push: ${{ github.event_name == 'pull_request' && github.repository == 'immich-app/immich' }}
+          cache-from: type=gha
+          cache-to: type=gha,mode=max
           tags: |
             altran1502/immich-server:staging
             altran1502/immich-server:${{ github.event.pull_request.number }}
@@ -64,6 +66,8 @@ jobs:
           file: ./machine-learning/Dockerfile
           platforms: linux/arm/v7,linux/amd64,linux/arm64
           push: ${{ github.event_name == 'pull_request' && github.repository == 'immich-app/immich' }}
+          cache-from: type=gha
+          cache-to: type=gha,mode=max
           tags: |
             altran1502/immich-machine-learning:staging
             altran1502/immich-machine-learning:${{ github.event.pull_request.number }}

+ 15 - 11
.github/workflows/build_push_server_release.yml

@@ -12,12 +12,12 @@ jobs:
       - name: Checkout
         uses: actions/checkout@v3
         with:
-          ref: "main"
+          ref: 'main'
           fetch-depth: 0
 
-      - name: "Get Previous tag"
+      - name: 'Get Previous tag'
         id: previoustag
-        uses: "WyriHaximus/github-action-get-previous-tag@v1"
+        uses: 'WyriHaximus/github-action-get-previous-tag@v1'
         with:
           fallback: latest
 
@@ -41,6 +41,8 @@ jobs:
           file: ./server/Dockerfile
           platforms: linux/arm/v7,linux/amd64,linux/arm64
           push: ${{ github.event_name != 'pull_request' }}
+          cache-from: type=gha
+          cache-to: type=gha,mode=max
           tags: |
             altran1502/immich-server:${{ steps.previoustag.outputs.tag }}
             altran1502/immich-server:release
@@ -52,9 +54,9 @@ jobs:
         uses: actions/checkout@v3
         with:
           fetch-depth: 0
-      - name: "Get Previous tag"
+      - name: 'Get Previous tag'
         id: previoustag
-        uses: "WyriHaximus/github-action-get-previous-tag@v1"
+        uses: 'WyriHaximus/github-action-get-previous-tag@v1'
         with:
           fallback: latest
       - name: Set up QEMU
@@ -74,6 +76,8 @@ jobs:
           file: ./machine-learning/Dockerfile
           platforms: linux/arm/v7,linux/amd64,linux/arm64
           push: true
+          cache-from: type=gha
+          cache-to: type=gha,mode=max
           tags: |
             altran1502/immich-machine-learning:${{ steps.previoustag.outputs.tag }}
             altran1502/immich-machine-learning:release
@@ -84,12 +88,12 @@ jobs:
       - name: Checkout
         uses: actions/checkout@v3
         with:
-          ref: "main"
+          ref: 'main'
           fetch-depth: 0
 
-      - name: "Get Previous tag"
+      - name: 'Get Previous tag'
         id: previoustag
-        uses: "WyriHaximus/github-action-get-previous-tag@v1"
+        uses: 'WyriHaximus/github-action-get-previous-tag@v1'
         with:
           fallback: latest
 
@@ -124,12 +128,12 @@ jobs:
       - name: Checkout
         uses: actions/checkout@v3
         with:
-          ref: "main"
+          ref: 'main'
           fetch-depth: 0
 
-      - name: "Get Previous tag"
+      - name: 'Get Previous tag'
         id: previoustag
-        uses: "WyriHaximus/github-action-get-previous-tag@v1"
+        uses: 'WyriHaximus/github-action-get-previous-tag@v1'
         with:
           fallback: latest
 

+ 3 - 3
docker/docker-compose.test.yml

@@ -1,4 +1,4 @@
-version: "3.8"
+version: '3.8'
 
 services:
   immich-server-test:
@@ -7,9 +7,9 @@ services:
       context: ../server
       dockerfile: Dockerfile
       target: builder
-    command: npm run test:e2e
+    command: npm ci && npm run test:e2e
     expose:
-      - "3000"
+      - '3000'
     volumes:
       - ../server:/usr/src/app
       - /usr/src/app/node_modules

+ 7 - 11
machine-learning/Dockerfile

@@ -6,18 +6,18 @@ ARG DEBIAN_FRONTEND=noninteractive
 
 WORKDIR /usr/src/app
 
-COPY package.json package-lock.json ./
-
 RUN apt-get update
 RUN apt-get install gcc g++ make cmake python3 python3-pip ffmpeg -y
 
+COPY package.json package-lock.json ./
+
 RUN npm ci
 RUN npm rebuild @tensorflow/tfjs-node --build-from-source
 
 COPY . .
 
 RUN npm run build
-
+RUN npm prune --omit=dev
 
 # Prod stage
 FROM node:16-bullseye-slim
@@ -26,18 +26,14 @@ ARG DEBIAN_FRONTEND=noninteractive
 
 WORKDIR /usr/src/app
 
-COPY package.json package-lock.json ./
-COPY entrypoint.sh ./
-
-RUN mkdir -p /usr/src/app/dist \
-  && mkdir -p /usr/src/app/node_modules \
-  && apt-get update \
+RUN apt-get update \
   && apt-get install -y ffmpeg \
   && rm -rf /var/cache/apt/lists
 
 COPY --from=builder /usr/src/app/node_modules ./node_modules
 COPY --from=builder /usr/src/app/dist ./dist
 
-RUN npm prune --production
+COPY package.json package-lock.json ./
+COPY entrypoint.sh ./
 
-# CMD [ "node", "dist/main" ]
+# CMD [ "node", "dist/main" ]

+ 8 - 9
server/Dockerfile

@@ -2,33 +2,32 @@ FROM node:16-alpine3.14 as builder
 
 WORKDIR /usr/src/app
 
+RUN apk add --update-cache build-base python3 libheif vips-dev ffmpeg
+
 COPY package.json package-lock.json ./
 
-RUN apk add --update-cache build-base python3 libheif vips-dev ffmpeg
 RUN npm ci
 
 COPY . .
 
 RUN npm run build
+RUN npm prune --omit=dev
 
 # Prod stage
 FROM node:16-alpine3.14
 
 WORKDIR /usr/src/app
-COPY LICENSE /licenses/LICENSE.txt
-COPY LICENSE /LICENSE
-
-COPY package.json package-lock.json ./
-COPY start-server.sh start-microservices.sh ./
 
-RUN mkdir -p /usr/src/app/dist \
-  && apk add --no-cache libheif vips ffmpeg
+RUN apk add --no-cache libheif vips ffmpeg
 
 COPY --from=builder /usr/src/app/node_modules ./node_modules
 COPY --from=builder /usr/src/app/dist ./dist
 COPY --from=builder /usr/src/app/bin ./bin
 
-RUN npm prune --production
+COPY LICENSE /licenses/LICENSE.txt
+COPY LICENSE /LICENSE
+COPY package.json package-lock.json ./
+COPY start-server.sh start-microservices.sh ./
 
 VOLUME /usr/src/app/upload