Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: Add Dockerfiles and build pipeline #146

Merged
merged 1 commit into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 95 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ jobs:
- name: Build package
run: npm run build
env:
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY: ${{ secrets.NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY }}
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY: ${{ secrets.CLOUD_PROD_CLERK_PUBLISHABLE_KEY }}

build-node:
needs: check_changes
Expand Down Expand Up @@ -401,3 +401,97 @@ jobs:
run: npm ci
- name: Run tests
run: npm test

build-app-image:
runs-on: ubuntu-latest
if: ${{ github.ref == 'refs/heads/main' }}
permissions:
id-token: write
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 App Docker Image
env:
IMAGE_TAG: ${{ github.sha }}
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: inferable-app
run: |
cd app
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" \
--build-arg="NEXT_PUBLIC_INFERABLE_API_URL=${{ vars.API_URL }}" \
--build-arg="NEXT_PUBLIC_APP_URL=${{ vars.APP_URL }}" \
--build-arg="NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=${{ secrets.CLOUD_PROD_CLERK_PUBLISHABLE_KEY }}" \
--build-arg="NEXT_PUBLIC_HYPERDX_API_KEY=${{ secrets.CLOUD_PROD_HYPERDX_API_KEY }}" \
--build-arg="NEXT_PUBLIC_POSTHOG_KEY=${{ secrets.CLOUD_PROD_POSTHOG_KEY }}" \
-t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG -t $ECR_REGISTRY/$ECR_REPOSITORY:latest ./

build-control-plane-image:
runs-on: ubuntu-latest
if: ${{ github.ref == 'refs/heads/main' }}
permissions:
id-token: write
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 Control Plane Docker Image
env:
IMAGE_TAG: ${{ github.sha }}
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: inferable-api
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }}
run: |
cd control-plane
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 ./
echo "Pushing Control Plane Image to Docker Hub"
docker login -u $DOCKERHUB_USERNAME -p $DOCKERHUB_PASSWORD
docker pull $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
docker tag $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG $DOCKERHUB_USERNAME/control-plane:$IMAGE_TAG
docker tag $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG $DOCKERHUB_USERNAME/control-plane:latest
docker push $DOCKERHUB_USERNAME/control-plane:$IMAGE_TAG
docker push $DOCKERHUB_USERNAME/control-plane: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.