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

Add dockerfile and docker-compose support #184

Merged
merged 16 commits into from
Aug 25, 2023
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
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
**/node_modules
**/bin
**/obj
79 changes: 79 additions & 0 deletions .github/workflows/copilot-build-images.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: copilot-build-images

on:
workflow_call:
inputs:
REACT_APP_BACKEND_URI:
required: true
type: string
REACT_APP_AAD_AUTHORITY:
required: true
type: string
REACT_APP_AAD_CLIENT_ID:
required: true
type: string
REACT_APP_AAD_API_SCOPE:
required: false
type: string
env:
REGISTRY: ghcr.io

jobs:
build-and-push-image:
name: Build and push images
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- file: ./docker/webapi/Dockerfile
image: ${{ github.repository }}-webapi
build-args: |

- file: ./docker/webapp/Dockerfile
image: ${{ github.repository }}-webapp
build-args: |

- file: ./docker/webapp/Dockerfile.nginx
image: ${{ github.repository }}-webapp-nginx
build-args: |
REACT_APP_BACKEND_URI=${{ inputs.REACT_APP_BACKEND_URI }}
REACT_APP_AAD_AUTHORITY=${{ inputs.REACT_APP_AAD_AUTHORITY }}
REACT_APP_AAD_CLIENT_ID=${{ inputs.REACT_APP_AAD_CLIENT_ID }}
REACT_APP_AAD_API_SCOPE=${{ inputs.REACT_APP_AAD_API_SCOPE }}
permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Login container registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels)
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/${{ matrix.image }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}
type=semver,pattern={{major}}.{{minor}}

- name: Build and push image
uses: docker/build-push-action@v3
with:
context: .
file: ${{ matrix.file }}
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: ${{ matrix.build-args }}
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -489,4 +489,4 @@ webapi/CopilotChatWebApi.sln
/deploy/

# Tesseract OCR language data files
*.traineddata
*.traineddata
33 changes: 33 additions & 0 deletions docker/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
version: '3'
services:
chat-copilot-webapp:
image: chat-copilot-webapp-nginx
build:
context: ..
dockerfile: docker/webapp/Dockerfile
ports:
- 3000:3000
env_file:
- ../webapp/.env
depends_on:
chat-copilot-webapi:
condition: service_started
chat-copilot-webapi:
image: chat-copilot-webapi
build:
context: ..
dockerfile: docker/webapi/Dockerfile
ports:
- 8080:8080
glahaye marked this conversation as resolved.
Show resolved Hide resolved
env_file:
- ../webapi/.env
environment:
- MemoryStore__Qdrant__Host=http://qdrant
depends_on:
qdrant:
condition: service_started
qdrant:
image: qdrant/qdrant
ports:
- 6333:6333

29 changes: 29 additions & 0 deletions docker/webapi/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# docker build -f docker/webapi/Dockerfile -t chat-copilot-webapi .

# Learn about building .NET container images:
# https://github.com/dotnet/dotnet-docker/blob/main/samples/README.md
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /source

# generate dev-certs for https
RUN dotnet dev-certs https

# copy csproj and restore as distinct layers
COPY webapi/*.csproj .
RUN dotnet restore --use-current-runtime

# copy everything else and build app
COPY webapi/. .
RUN apt update && apt install -y wget
RUN wget -P data https://raw.githubusercontent.com/tesseract-ocr/tessdata/main/eng.traineddata
RUN dotnet publish --use-current-runtime --self-contained false --no-restore -o /app


# final stage/image
FROM mcr.microsoft.com/dotnet/aspnet:6.0
ENV Kestrel__Endpoints__Http__Url=http://0.0.0.0:8080
WORKDIR /app
COPY --from=build /app .
COPY --from=build /root/.dotnet/corefx/cryptography/x509stores/my/* /root/.dotnet/corefx/cryptography/x509stores/my/

ENTRYPOINT ["./CopilotChatWebApi"]
19 changes: 19 additions & 0 deletions docker/webapp/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# docker build -f docker/webapp/Dockerfile -t chat-copilot-webapp .

# builder
FROM node:lts-alpine as builder
WORKDIR /app
COPY webapp/ .
RUN yarn install \
--prefer-offline \
--frozen-lockfile \
--non-interactive \
--production=false
huangyingting marked this conversation as resolved.
Show resolved Hide resolved

# final stage/image
FROM node:lts-alpine
WORKDIR /app
COPY --from=builder /app .
ENV HOST 0.0.0.0
EXPOSE 3000
ENTRYPOINT [ "yarn", "start" ]
34 changes: 34 additions & 0 deletions docker/webapp/Dockerfile.nginx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# source webapp/.env
# docker build --build-arg REACT_APP_BACKEND_URI=$REACT_APP_BACKEND_URI --build-arg REACT_APP_AAD_AUTHORITY=$REACT_APP_AAD_AUTHORITY --build-arg REACT_APP_AAD_CLIENT_ID=$REACT_APP_AAD_CLIENT_ID --build-arg REACT_APP_AAD_API_SCOPE=$REACT_APP_AAD_API_SCOPE -f docker/webapp/Dockerfile.nginx -t chat-copilot-webapp-nginx .

# builder
FROM node:lts-alpine as builder

ARG REACT_APP_BACKEND_URI
ENV REACT_APP_BACKEND_URI $REACT_APP_BACKEND_URI

ARG REACT_APP_AAD_AUTHORITY
ENV REACT_APP_AAD_AUTHORITY $REACT_APP_AAD_AUTHORITY

ARG REACT_APP_AAD_CLIENT_ID
ENV REACT_APP_AAD_CLIENT_ID $REACT_APP_AAD_CLIENT_ID

ARG REACT_APP_AAD_API_SCOPE
ENV REACT_APP_AAD_API_SCOPE $REACT_APP_AAD_API_SCOPE

WORKDIR /app
COPY webapp/ .
RUN yarn install \
--prefer-offline \
--frozen-lockfile \
--non-interactive \
--production=true

RUN yarn build

# final stage/image
FROM nginx:stable-alpine
EXPOSE 3000
RUN sed -i 's/80/3000/g' /etc/nginx/conf.d/default.conf
COPY --from=builder /app/build /usr/share/nginx/html
CMD ["nginx", "-g", "daemon off;"]