diff --git a/.github/workflows/docker_release.yml b/.github/workflows/docker_release.yml index cae845c..f17a283 100644 --- a/.github/workflows/docker_release.yml +++ b/.github/workflows/docker_release.yml @@ -12,6 +12,17 @@ jobs: - name: Checkout code uses: actions/checkout@v2 + - name: Setup Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Cache Docker layers + uses: actions/cache@v2 + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-buildx-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-buildx- + - name: Login to DockerHub uses: docker/login-action@v1 with: @@ -22,8 +33,10 @@ jobs: run: echo "RELEASE_VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV - name: Build and Push Docker Image - run: | - docker build -t mariusbegby/cadence:${{ env.RELEASE_VERSION }} . - docker tag mariusbegby/cadence:${{ env.RELEASE_VERSION }} mariusbegby/cadence:latest - docker push mariusbegby/cadence:${{ env.RELEASE_VERSION }} - docker push mariusbegby/cadence:latest + uses: docker/build-push-action@v2 + with: + context: . + push: true + tags: mariusbegby/cadence:${{ env.RELEASE_VERSION }}, mariusbegby/cadence:latest + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index 36e6c78..05c3fa0 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -26,5 +26,6 @@ jobs: node-version: ${{ matrix.node-version }} cache: 'npm' - run: npm install -g npm@latest - - run: npm ci --legacy-peer-deps + - run: npm ci - run: npm run eslint + - run: npm run build diff --git a/Dockerfile b/Dockerfile index c4f5648..e60980d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,16 +13,24 @@ RUN apk add --no-cache python3 make build-base ffmpeg WORKDIR /cadence-discord-bot # Copy the rest of the source files into the image. -COPY . . +COPY package*.json ./ +COPY tsconfig.json ./ +COPY src/ ./src/ +COPY config/ ./config/ # Install dependencies from package-lock.json and omit dev dependencies # Leverage a cache mount to /root/.npm to speed up subsequent builds. RUN --mount=type=cache,target=/root/.npm \ + npm ci + +# Transpile TypeScript to JavaScript, remove dev dependencies, and install production dependencies +RUN npm run build && \ + rm -rf node_modules && \ npm ci --omit=dev -# Cleanup of unneeded packages and apk cache +# Cleanup of unneeded packages, apk cache, and TypeScript source files RUN apk del python3 make build-base && \ - rm -rf /var/cache/apk/* /tmp/* + rm -rf /var/cache/apk/* /tmp/* ./src/ # Startup command to run the bot after deploying slash commands CMD /bin/sh -c "npm run deploy && npm run start" diff --git a/package-lock.json b/package-lock.json index f2d867b..afebc98 100644 --- a/package-lock.json +++ b/package-lock.json @@ -28,7 +28,6 @@ "@types/config": "^3.3.0", "@types/node": "^20.5.6", "@types/node-os-utils": "^1.3.1", - "@types/pino": "^7.0.5", "@types/uuid": "^9.0.2", "@typescript-eslint/eslint-plugin": "^6.4.1", "eslint": "^8.47.0", @@ -480,16 +479,6 @@ "integrity": "sha512-gokG1AaQo78X3f1KXOPAfwbhERX95XL0nhosOhwFck0hZ3BG52Mfch3oj3gAhXuUsou3lwi+ewZWjDo0wshKwQ==", "dev": true }, - "node_modules/@types/pino": { - "version": "7.0.5", - "resolved": "https://registry.npmjs.org/@types/pino/-/pino-7.0.5.tgz", - "integrity": "sha512-wKoab31pknvILkxAF8ss+v9iNyhw5Iu/0jLtRkUD74cNfOOLJNnqfFKAv0r7wVaTQxRZtWrMpGfShwwBjOcgcg==", - "deprecated": "This is a stub types definition. pino provides its own type definitions, so you do not need this installed.", - "dev": true, - "dependencies": { - "pino": "*" - } - }, "node_modules/@types/prettier": { "version": "2.7.3", "resolved": "https://registry.npmjs.org/@types/prettier/-/prettier-2.7.3.tgz", diff --git a/package.json b/package.json index 511b4ee..8a257b8 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,8 @@ "start-pretty-no-ignore": "node ./dist/index.js | pino-pretty", "deploy": "node ./dist/utils/deploySlashCommands.js", "deploy-pretty": "node ./dist/utils/deploySlashCommands.js | pino-pretty --ignore environment,source,module,action,name,context,executionId,shardId,guildId", - "eslint": "eslint ./src" + "eslint": "eslint ./src", + "build": "tsc" }, "dependencies": { "@discord-player/extractor": "^4.4.2-dev.1", @@ -46,7 +47,6 @@ "@types/config": "^3.3.0", "@types/node": "^20.5.6", "@types/node-os-utils": "^1.3.1", - "@types/pino": "^7.0.5", "@types/uuid": "^9.0.2", "@typescript-eslint/eslint-plugin": "^6.4.1", "eslint": "^8.47.0",