Skip to content

Commit

Permalink
ci: Add Dockerfiles and build pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
johnjcsmith committed Nov 28, 2024
1 parent 9c9287f commit 439029b
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 28 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -401,3 +401,39 @@ jobs:
run: npm ci
- name: Run tests
run: npm test

build-images:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_ROLE_ARN }}
aws-region: us-east-1

- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Build, tag, and push image to Amazon ECR
env:
IMAGE_TAG: ${{ github.sha }}
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: inferable-control-plane
run: |
VERSION=${{ github.sha }}
SHORT_VERSION=$(echo ${{ github.sha }} | cut -c 1-6)
docker buildx build \
--target run \
--push \
--cache-to mode=min,image-manifest=true,oci-mediatypes=true,type=registry,ref=$ECR_REGISTRY/$ECR_REPOSITORY:cache \
--cache-from type=registry,ref=$ECR_REGISTRY/$ECR_REPOSITORY:cache \
--build-arg="VERSION=$VERSION" \
--build-arg="SHORT_VERSION=$SHORT_VERSION" \
-t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG -t $ECR_REGISTRY/$ECR_REPOSITORY:latest ./
55 changes: 55 additions & 0 deletions app/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# syntax = docker/dockerfile:1

ARG NODE_VERSION=20.11.1

FROM node:${NODE_VERSION}-slim AS base
WORKDIR /app

FROM base AS build
WORKDIR /build
RUN apt-get update -qq && \
apt-get install --no-install-recommends -y build-essential node-gyp pkg-config python-is-python3

COPY --link ./ /build/

RUN npm ci

ARG NEXT_PUBLIC_INFERABLE_API_URL
ENV NEXT_PUBLIC_INFERABLE_API_URL=$NEXT_PUBLIC_INFERABLE_API_URL

ARG NEXT_PUBLIC_APP_URL
ENV NEXT_PUBLIC_APP_URL=$NEXT_PUBLIC_APP_URL

ARG NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY
ENV NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=$NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY

ARG NEXT_PUBLIC_HYPERDX_API_KEY
ENV NEXT_PUBLIC_HYPERDX_API_KEY=$NEXT_PUBLIC_HYPERDX_API_KEY

ARG NEXT_PUBLIC_POSTHOG_KEY
ENV NEXT_PUBLIC_POSTHOG_KEY=$NEXT_PUBLIC_POSTHOG_KEY
ENV NEXT_PUBLIC_POSTHOG_HOST="https://www.inferable.ai/ingest"

RUN npm run build
RUN npm prune --omit=dev

FROM base AS run

# Install curl for healthchecks
RUN apt-get update -qq && \
apt-get install -y curl && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

ARG VERSION
ENV VERSION=$VERSION

ARG SHORT_VERSION
ENV SHORT_VERSION=$SHORT_VERSION

COPY --from=build /build/ /app

ENV NODE_ENV=production

EXPOSE 3001
CMD [ "node", "server.js" ]
16 changes: 0 additions & 16 deletions app/Dockerfile.dev

This file was deleted.

39 changes: 39 additions & 0 deletions control-plane/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# syntax = docker/dockerfile:1

ARG NODE_VERSION=20.11.1

FROM node:${NODE_VERSION}-slim AS base
WORKDIR /app

FROM base AS build
WORKDIR /build
RUN apt-get update -qq && \
apt-get install --no-install-recommends -y build-essential node-gyp pkg-config python-is-python3

COPY --link ./ /build

RUN npm ci

RUN npm run build
RUN npm prune --omit=dev

FROM base AS run

# Install curl for healthchecks
RUN apt-get update -qq && \
apt-get install -y curl && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

ARG VERSION
ENV VERSION=$VERSION

ARG SHORT_VERSION
ENV SHORT_VERSION=$SHORT_VERSION

COPY --from=build /build/ /app

ENV NODE_ENV=production

EXPOSE 4000
CMD [ "npm", "run", "start" ]
12 changes: 0 additions & 12 deletions control-plane/Dockerfile.dev

This file was deleted.

0 comments on commit 439029b

Please sign in to comment.