Kaynağa Gözat

@uppy/companion: fix Dockerfile and deploy automation (#3355)

* attempt at fixing dockerfile

that works with yarn workspaces and respects yarn.lock

* run corepack yarn

* update Dockerfile references

* remove unneccesary yarn plugin import

* Apply suggestions from code review

Co-authored-by: Antoine du Hamel <duhamelantoine1995@gmail.com>

Co-authored-by: Antoine du Hamel <duhamelantoine1995@gmail.com>
Mikael Finstad 3 yıl önce
ebeveyn
işleme
bac107fc5f

+ 4 - 0
.dockerignore

@@ -0,0 +1,4 @@
+**/node_modules
+.git
+website
+assets

+ 2 - 2
.github/workflows/companion-deploy.yml

@@ -32,8 +32,8 @@ jobs:
         uses: docker/build-push-action@v2
         with:
           push: true
-          context: packages/@uppy/companion
-          file: packages/@uppy/companion/Dockerfile
+          context: .
+          file: Dockerfile
           tags: ${{ steps.docker_meta.outputs.tags }}
           labels: ${{ steps.docker_meta.outputs.labels }}
 

+ 33 - 0
Dockerfile

@@ -0,0 +1,33 @@
+FROM node:16.13.0-alpine as build
+
+WORKDIR /app
+
+COPY package.json .yarnrc.yml /app/
+COPY .yarn /app/.yarn
+COPY packages/@uppy/companion /app/packages/@uppy/companion
+
+RUN apk --update add  --virtual native-dep \
+  make gcc g++ python3 libgcc libstdc++ git && \
+  (cd /app && corepack yarn workspaces focus @uppy/companion) && \
+  apk del native-dep
+
+RUN cd /app && corepack yarn workspace @uppy/companion build
+
+# Now remove all non-prod dependencies for a leaner image
+RUN cd /app && corepack yarn workspaces focus @uppy/companion --production
+
+FROM node:16.13.0-alpine
+
+WORKDIR /app
+
+# copy required files from build stage.
+COPY --from=build /app/packages/@uppy/companion/bin /app/bin
+COPY --from=build /app/packages/@uppy/companion/lib /app/lib
+COPY --from=build /app/packages/@uppy/companion/package.json /app/package.json
+COPY --from=build /app/packages/@uppy/companion/node_modules /app/node_modules
+
+ENV PATH "${PATH}:/app/node_modules/.bin"
+
+CMD ["node","/app/bin/companion"]
+# This can be overruled later
+EXPOSE 3020

+ 0 - 0
packages/@uppy/companion/Dockerfile.test → Dockerfile.test


+ 0 - 0
packages/@uppy/companion/docker-compose-dev.yml → docker-compose-dev.yml


+ 0 - 0
packages/@uppy/companion/docker-compose-test.yml → docker-compose-test.yml


+ 0 - 0
packages/@uppy/companion/docker-compose.yml → docker-compose.yml


+ 1 - 0
package.json

@@ -190,6 +190,7 @@
     ]
   },
   "resolutions": {
+    "@types/redis": "2",
     "@types/eslint@^7.2.13": "^8.2.0",
     "npm-auth-to-token@1.0.0": "patch:npm-auth-to-token@npm:1.0.0#.yarn/patches/npm-auth-to-token-npm-1.0.0-c288ce201f"
   }

+ 0 - 1
packages/@uppy/companion/.dockerignore

@@ -1 +0,0 @@
-node_modules

+ 0 - 35
packages/@uppy/companion/Dockerfile

@@ -1,35 +0,0 @@
-FROM node:16.13.0-alpine as build
-
-COPY package.json /app/package.json
-
-WORKDIR /app
-
-# Install node_modules
-# * to optionally copy lock files that _might_ _not_ exist
-ADD package.json package-*.json yarn.* /tmp/
-RUN cd /tmp && apk --update add  --virtual native-dep \
-  make gcc g++ python3 libgcc libstdc++ git && \
-  corepack yarn install && \
-  apk del native-dep
-RUN mkdir -p /app && cd /app && ln -nfs /tmp/node_modules
-RUN apk add bash
-COPY . /app
-ENV PATH "${PATH}:/app/node_modules/.bin"
-RUN corepack yarn run build
-
-FROM node:16.13.0-alpine
-
-RUN mkdir -p /app
-WORKDIR /app
-
-# copy required files from build stage.
-COPY --from=build /app/bin /app/bin
-COPY --from=build /app/lib /app/lib
-COPY --from=build /app/package.json /app/package.json
-COPY --from=build /tmp/node_modules /app/node_modules
-
-ENV PATH "${PATH}:/app/node_modules/.bin"
-
-CMD ["node","/app/bin/companion"]
-# This can be overruled later
-EXPOSE 3020

+ 1 - 1
packages/@uppy/companion/infra/kube/gcloud-deploy.sh

@@ -17,7 +17,7 @@ mv ./kubectl ${HOME}/.local/bin/
 
 
 # Store the new image in docker hub
-docker build -t transloadit/companion:latest -t transloadit/companion:$TRAVIS_COMMIT -f packages/@uppy/companion/Dockerfile packages/@uppy/companion;
+docker build -t transloadit/companion:latest -t transloadit/companion:$TRAVIS_COMMIT .;
 docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD";
 
 # Push the commit tagged docker image.

+ 3 - 0
packages/@uppy/companion/package.json

@@ -114,5 +114,8 @@
   },
   "engines": {
     "node": ">=10.20.1"
+  },
+  "installConfig": {
+    "hoistingLimits": "workspaces"
   }
 }

+ 1 - 1
yarn.lock

@@ -6783,7 +6783,7 @@ __metadata:
   languageName: node
   linkType: hard
 
-"@types/redis@npm:*":
+"@types/redis@npm:2":
   version: 2.8.32
   resolution: "@types/redis@npm:2.8.32"
   dependencies: