diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..891a24d --- /dev/null +++ b/.dockerignore @@ -0,0 +1,13 @@ +# Ignore everything +* + +# Allow files and directories +!/backend +!/yarn.lock + +# Ignore unnecessary files inside allowed directories +# This should go after the allowed directories +**/node_modules +**/*.zip +**/*.tar +**/.env \ No newline at end of file diff --git a/backend/Dockerfile b/backend/Dockerfile index 187c6cf..f742d9a 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -2,8 +2,8 @@ FROM node:18-alpine As development WORKDIR /usr/src/app -COPY --chown=node:node package.json ./ -COPY --chown=node:node ../yarn.lock ./ +COPY --chown=node:node backend/package.json ./ +COPY --chown=node:node yarn.lock ./ RUN yarn install --frozen-lockfile --immutable --non-interactive --prefer-offline @@ -15,11 +15,11 @@ WORKDIR /usr/src/app COPY --chown=node:node --from=development /usr/src/app/ . -COPY --chown=node:node . . +COPY --chown=node:node backend . RUN yarn run build -user node +USER node FROM node:18-alpine As productionDeps @@ -28,8 +28,8 @@ WORKDIR /usr/src/app ENV NODE_ENV production ENV NO_COLOR true -COPY --chown=node:node package.json ./ -COPY --chown=node:node ../yarn.lock ./ +COPY --chown=node:node backend/package.json ./ +COPY --chown=node:node yarn.lock ./ RUN yarn install --frozen-lockfile --immutable --non-interactive --prefer-offline --production && yarn cache clean --force diff --git a/backend/package.json b/backend/package.json index c1f875e..b1bb8fa 100644 --- a/backend/package.json +++ b/backend/package.json @@ -6,7 +6,7 @@ "private": "true", "scripts": { "build": "tsc", - "build:release": "cp ../yarn.lock ./ && docker build -t cloud-http-proxy . && docker save cloud-http-proxy -o image.tar && zip ../cloud-http-proxy cumulocity.json image.tar", + "build:release": "docker build -t cloud-http-proxy -f ./Dockerfile .. && docker save cloud-http-proxy -o image.tar && zip ../cloud-http-proxy cumulocity.json image.tar", "dev": "tsx watch src/index.ts", "start": "ts-node src/index.ts", "start:docker": "docker run -it -p 3000:3000 --name http-proxy --env-file .env cloud-http-proxy",