Skip to content

Commit

Permalink
fix: deployment pipeline for docker not working (#860)
Browse files Browse the repository at this point in the history
* fix: skip env validation in dockerfile not working

* fix: skip env validation in dockerfile not working

* fix: remove linux/arm/v7 for now as node commands are run forever

* fix: remove cache because it is to big?

* refactor: remove redis log transport during build

* fix: add more checks for conditional redis connection

* fix: docker build not working locally

* refactor: move base image to debian

* chore: add arm v7 platform support

* fix: remove armv7 support as not supported by turbo

* chore: profile amd64 build

* chore: enable webpack logging

* chore: disable linux/arm64 for now

* chore: remove profiling from build in dockerfile

* chore: revert to node alpine image
  • Loading branch information
Meierschlumpf authored Jul 25, 2024
1 parent 32a8488 commit 90ef982
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 18 deletions.
8 changes: 1 addition & 7 deletions .github/workflows/deployment-docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,6 @@ jobs:
with:
node-version: ${{ matrix.node-version }}
cache: "pnpm"
- name: Install dependencies
run: pnpm install
- name: Build artifacts
run: pnpm build
- name: Discord notification
if: ${{ github.events.inputs.send-notifications }}
env:
Expand All @@ -90,13 +86,11 @@ jobs:
id: buildPushAction
uses: docker/build-push-action@v6
with:
platforms: linux/amd64,linux/arm64,linux/arm/v7
platforms: linux/amd64 # we currently do't build for linux/arm64 as it's really slow and we'll move to a self hosted runner for that or use the official github runner, once it's available
context: .
push: false
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
network: host
env:
SKIP_ENV_VALIDATION: true
Expand Down
9 changes: 6 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ FROM node:20.16.0-alpine AS base
FROM base AS builder
RUN apk add --no-cache libc6-compat
RUN apk update

# Set working directory
WORKDIR /app
COPY . .
Expand Down Expand Up @@ -35,6 +36,7 @@ RUN corepack enable pnpm && pnpm install

COPY --from=builder /app/next-out/json/ .
COPY --from=builder /app/next-out/pnpm-lock.yaml ./pnpm-lock.yaml
RUN corepack enable pnpm && pnpm install

RUN corepack enable pnpm && pnpm install sharp -w

Expand All @@ -46,8 +48,9 @@ COPY --from=builder /app/migration-out/full/ .

# Copy static data as it is not part of the build
COPY static-data ./static-data
ARG SKIP_ENV_VALIDATION=true
RUN corepack enable pnpm && pnpm turbo run build
ARG SKIP_ENV_VALIDATION='true'
ARG DISABLE_REDIS_LOGS='true'
RUN corepack enable pnpm && pnpm build

FROM base AS runner
WORKDIR /app
Expand Down Expand Up @@ -84,6 +87,6 @@ COPY --chown=nextjs:nodejs packages/redis/redis.conf /app/redis.conf
ENV DB_URL='/appdata/db/db.sqlite'
ENV DB_DIALECT='sqlite'
ENV DB_DRIVER='better-sqlite3'
ENV AUTH_PROVIDERS=credentials
ENV AUTH_PROVIDERS='credentials'

CMD ["sh", "run.sh"]
13 changes: 8 additions & 5 deletions apps/nextjs/next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ const config = {
/** We already do linting and typechecking as separate tasks in CI */
eslint: { ignoreDuringBuilds: true },
typescript: { ignoreBuildErrors: true },
webpack: (config) => {
config.module.rules.push({
test: /\.node$/,
loader: "node-loader",
});
webpack: (config, { isServer }) => {
if (isServer) {
config.module.rules.push({
test: /\.node$/,
loader: "node-loader",
});
}

return config;
},
experimental: {
Expand Down
2 changes: 1 addition & 1 deletion development/docker-run.cmd
Original file line number Diff line number Diff line change
@@ -1 +1 @@
docker run -p 3000:3000 -p 3001:3001 homarr:latest
docker run -p 3000:3000 -p 3001:3001 -e AUTH_SECRET='secrets' homarr:latest
9 changes: 8 additions & 1 deletion packages/log/src/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,16 @@ const logMessageFormat = format.printf(({ level, message, timestamp }) => {
return `${timestamp} ${level}: ${message}`;
});

const logTransports = [new transports.Console()];

// Only add the Redis transport if we are not in CI
if (!(Boolean(process.env.CI) || Boolean(process.env.DISABLE_REDIS_LOGS))) {
logTransports.push(new RedisTransport());
}

const logger = winston.createLogger({
format: format.combine(format.colorize(), format.timestamp(), logMessageFormat),
transports: [new transports.Console(), new RedisTransport()],
transports: logTransports,
});

export { logger };
9 changes: 8 additions & 1 deletion packages/redis/src/lib/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,11 @@ import { Redis } from "ioredis";
* Creates a new Redis connection
* @returns redis client
*/
export const createRedisConnection = () => new Redis();
export const createRedisConnection = () => {
if (Boolean(process.env.CI) || Boolean(process.env.DISABLE_REDIS_LOGS)) {
// Return null if we are in CI as we don't want to connect to Redis
return null as unknown as Redis;
}

return new Redis();
};
1 change: 1 addition & 0 deletions turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"AUTH_PROVIDERS",
"AUTH_SECRET",
"CI",
"DISABLE_REDIS_LOGS",
"DB_URL",
"DB_HOST",
"DB_USER",
Expand Down

0 comments on commit 90ef982

Please sign in to comment.