Skip to content

Commit

Permalink
Fixing docker file (#62)
Browse files Browse the repository at this point in the history
* Fixing docker file

* Attempt #2 electric boogaloo

* Fix #3 lets gooo

* #5...

* Mb now its #5, fixing directory path

* #6 copying over tsconfig files

* Removing test branch trigger
  • Loading branch information
dominicwest authored Oct 24, 2023
1 parent a3bdbf9 commit 6f1f89b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 46 deletions.
22 changes: 11 additions & 11 deletions .github/workflows/pushImage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
runs-on: ubuntu-latest

outputs:
docker-image-name: ${{ steps.docker-image-name.outputs.name }}
docker-image-name: ${{ steps.docker-image-name.outputs.name }}

steps:
- uses: actions/checkout@v3
Expand All @@ -78,26 +78,26 @@ jobs:
- name: Build Docker image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
run: docker build -t $ECR_REGISTRY/find-a-grant-api:${{ env.BUILD_VERSION }} .

- name: Generate Docker image name
id: docker-image-name
run: |
NAME=${{ (github.ref == 'refs/heads/develop' && 'find-api-dev-image') || (startsWith(github.ref, 'refs/heads/release') && 'find-api-qa-image') }}
echo "name=$NAME" >> $GITHUB_OUTPUT
NAME=${{ (github.ref == 'refs/heads/develop' && 'find-api-dev-image') || (startsWith(github.ref, 'refs/heads/release') && 'find-api-qa-image') }}
echo "name=$NAME" >> $GITHUB_OUTPUT
- name: Save Docker image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
run: docker save --output ${{ steps.docker-image-name.outputs.name }}.tar $ECR_REGISTRY/find-a-grant-api:${{ env.BUILD_VERSION }}

- name: Upload Docker image
uses: actions/upload-artifact@v3
with:
name: ${{ steps.docker-image-name.outputs.name }}
path: ${{ steps.docker-image-name.outputs.name }}.tar
retention-days: 1
name: ${{ steps.docker-image-name.outputs.name }}
path: ${{ steps.docker-image-name.outputs.name }}.tar
retention-days: 1

deploy:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -130,7 +130,7 @@ jobs:
- name: Download Docker image
uses: actions/download-artifact@v3
with:
name: ${{ needs.build.outputs.docker-image-name }}
name: ${{ needs.build.outputs.docker-image-name }}

- name: Load Docker image
run: docker load --input ${{ needs.build.outputs.docker-image-name }}.tar
Expand Down
43 changes: 8 additions & 35 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,52 +1,25 @@
# Install dependencies only when needed
FROM node:16-alpine AS deps
FROM node:16-alpine AS build
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
RUN apk add --no-cache libc6-compat
WORKDIR /app


RUN echo -e "\nnodeLinker: node-modules" >> .yarnrc.yml
WORKDIR /app

# Install dependencies based on the preferred package manager
COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./
RUN \
if [ -f yarn.lock ]; then yarn set version berry && yarn --immutable; \
elif [ -f package-lock.json ]; then npm ci; \
elif [ -f pnpm-lock.yaml ]; then yarn global add pnpm && pnpm i --frozen-lockfile; \
else echo "Lockfile not found." && exit 1; \
fi
COPY package.json .
COPY yarn.lock .
COPY tsconfig.build.json .
COPY tsconfig.json .

#temp debug
RUN yarn -v
RUN ls -a
RUN ls -a /app/
RUN cat .yarnrc.yml

# Rebuild the source code only when needed
FROM node:16-alpine AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
RUN yarn install --immutable

RUN yarn build


FROM node:16-alpine AS runner
WORKDIR /app

ENV NODE_ENV production

# Install dependencies based on the preferred package manager
COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./
RUN \
if [ -f yarn.lock ]; then yarn --immutable; \
elif [ -f package-lock.json ]; then npm ci; \
elif [ -f pnpm-lock.yaml ]; then yarn global add pnpm && pnpm i --frozen-lockfile; \
else echo "Lockfile not found." && exit 1; \
fi

# Copy production build
COPY --from=builder /app/dist/ ./dist/
COPY --from=build /app/dist/ ./dist/

# Expose application port
EXPOSE 3000
Expand Down

0 comments on commit 6f1f89b

Please sign in to comment.