Skip to content

Commit

Permalink
Update docker build
Browse files Browse the repository at this point in the history
  • Loading branch information
DanPaseltiner committed Oct 11, 2024
1 parent ec10c79 commit ea530fa
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 42 deletions.
55 changes: 16 additions & 39 deletions containers/tefca-viewer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,29 +1,16 @@
FROM node:18-alpine AS base

FROM base AS builder
# Install necessary packages for building
FROM base AS installer

RUN apk update
RUN apk add --no-cache libc6-compat
RUN apk add --no-cache bash curl

# Set working directory
WORKDIR /app
RUN npm i -g turbo
COPY . .
ENV TURBO_TELEMETRY_DISABLED=1
RUN turbo prune tefca-viewer --docker

# Add lockfile and package.json's of isolated subworkspace
FROM base AS installer
RUN apk update
RUN apk add --no-cache libc6-compat
WORKDIR /app

ENV FLYWAY_VERSION=10.19.0

# Add bash to enable running Flyway
RUN apk add --no-cache bash curl

# Install Flyway and remove JRE directory to force flyway to use the openjdk11 version in the runner
ENV FLYWAY_VERSION=10.19.0
RUN curl -L https://repo1.maven.org/maven2/org/flywaydb/flyway-commandline/${FLYWAY_VERSION}/flyway-commandline-${FLYWAY_VERSION}-linux-x64.tar.gz -o flyway.tar.gz \
&& tar -zxvf flyway.tar.gz \
&& mv flyway-${FLYWAY_VERSION} /flyway \
Expand All @@ -32,19 +19,10 @@ RUN curl -L https://repo1.maven.org/maven2/org/flywaydb/flyway-commandline/${FLY
&& rm -rf /flyway/jre \
&& chmod +x /flyway/flyway

# First install the dependencies
COPY .gitignore .gitignore
COPY --from=builder /app/out/json/ .
COPY --from=builder /app/out/package-lock.json ./package-lock.json
RUN npm i

# Build the project
COPY --from=builder /app/out/full/ .
COPY turbo.json turbo.json
ENV NEXT_TELEMETRY_DISABLED=1
ENV TURBO_TELEMETRY_DISABLED=1

RUN npx turbo build --filter=tefca-viewer...
RUN npm ci
RUN npm run build

# Final stage for running the app
FROM base AS runner
Expand All @@ -64,26 +42,25 @@ RUN adduser --system --uid 1001 nextjs
USER nextjs

# Set hostname to localhost
ENV HOSTNAME "0.0.0.0"
ENV HOSTNAME="0.0.0.0"

# Copy necessary app files
COPY --from=installer /app/containers/tefca-viewer/next.config.js .
COPY --from=installer /app/containers/tefca-viewer/package.json .
COPY --from=installer /app/containers/tefca-viewer/flyway/conf/flyway.conf /flyway/conf/flyway.conf
COPY --from=installer /app/containers/tefca-viewer/flyway/sql /flyway/sql
COPY --from=installer /app/next.config.js .
COPY --from=installer /app/package.json .
COPY --from=installer /app/flyway/conf/flyway.conf ./flyway/conf/flyway.conf
COPY --from=installer /app/flyway/sql ./flyway/sql

# Automatically leverage output traces to reduce image size
COPY --from=installer --chown=nextjs:nodejs /app/containers/tefca-viewer/.next/standalone ./
COPY --from=installer --chown=nextjs:nodejs /app/containers/tefca-viewer/.next/static ./containers/tefca-viewer/.next/static
COPY --from=installer --chown=nextjs:nodejs /app/containers/tefca-viewer/public ./containers/tefca-viewer/public

COPY --from=installer --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=installer --chown=nextjs:nodejs /app/.next/static ./.next/static
COPY --from=installer --chown=nextjs:nodejs /app/public ./public
RUN ls -R
# Set environment variables for Flyway and Node.js telemetry
ENV TURBO_TELEMETRY_DISABLED=1
ENV NEXT_TELEMETRY_DISABLED=1

# Set JAVA_HOME to the OpenJDK version installed by apk for Flyway
ENV JAVA_HOME=/usr/lib/jvm/default-jvm
# Add the OpenJDK to the PATH so the java command is available for Flways
ENV PATH=$JAVA_HOME/bin:$PATH

CMD ["sh", "-c","flyway -configFiles=/flyway/conf/flyway.conf -schemas=public -connectRetries=60 migrate && echo done with flyway && node containers/tefca-viewer/server.js"]
CMD ["sh", "-c","flyway -configFiles=./flyway/conf/flyway.conf -schemas=public -connectRetries=60 migrate && echo done with flyway && node server.js"]
1 change: 1 addition & 0 deletions containers/tefca-viewer/docker-compose-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ services:
flyway:
image: flyway/flyway:10.16-alpine
command: -configFiles=/flyway/conf/flyway.conf -schemas=public -connectRetries=60 migrate
platform: linux/amd64
volumes:
- ./flyway/sql:/flyway/sql
- ./flyway/conf/flyway.conf:/flyway/conf/flyway.conf
Expand Down
4 changes: 2 additions & 2 deletions containers/tefca-viewer/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ services:
tefca-viewer:
platform: linux/amd64
build:
context: ../../
dockerfile: ./containers/tefca-viewer/Dockerfile
context: .
dockerfile: Dockerfile
tty: true
ports:
- "3000:3000"
Expand Down
2 changes: 1 addition & 1 deletion containers/tefca-viewer/flyway/conf/flyway.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
flyway.url=jdbc:postgresql://db:5432/tefca_db
flyway.locations=filesystem:/flyway/sql
flyway.locations=filesystem:./flyway/sql
flyway.user=postgres
flyway.password=pw
flyway.baselineOnMigrate=false

0 comments on commit ea530fa

Please sign in to comment.