Skip to content

Commit 7a93e53

Browse files
Add dockerfile and docker-compose support (#184)
### Motivation and Context Adding docker support to deploy into kubernetes or run in local docker environment ### Description Adding docker support to deploy into kubernetes or run in local docker environment. A new folder "docker" created under root, to build images, from root directory, run `docker build -f docker/webapi/Dockerfile -t repo/chat-copilot-webapi` `docker build -f docker/webapi/Dockerfile -t repo/chat-copilot-webapp` A docker-compose file is also created to start whole environment, under docker directory, just run `docker-compose up`, it uses .env file to read environment variables, so make sure webapi and webapp directory has .env file the manifests to deply chat-copilot into kubernetes environment can be found here https://github.com/huangyingting/flux2-gitops/tree/main/apps/base/chat-copilot ### Contribution Checklist <!-- Before submitting this PR, please make sure: --> - [x] The code builds clean without any errors or warnings - [x] The PR follows the [Contribution Guidelines](https://github.com/microsoft/copilot-chat/blob/main/CONTRIBUTING.md) and the [pre-submission formatting script](https://github.com/microsoft/copilot-chat/blob/main/CONTRIBUTING.md#development-scripts) raises no violations - [x] All unit tests pass, and I have added new tests where possible - [x] I didn't break anyone 😄
1 parent 3838fca commit 7a93e53

File tree

7 files changed

+198
-1
lines changed

7 files changed

+198
-1
lines changed

.dockerignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
**/node_modules
2+
**/bin
3+
**/obj
+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
name: copilot-build-images
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
REACT_APP_BACKEND_URI:
7+
required: true
8+
type: string
9+
REACT_APP_AAD_AUTHORITY:
10+
required: true
11+
type: string
12+
REACT_APP_AAD_CLIENT_ID:
13+
required: true
14+
type: string
15+
REACT_APP_AAD_API_SCOPE:
16+
required: false
17+
type: string
18+
env:
19+
REGISTRY: ghcr.io
20+
21+
jobs:
22+
build-and-push-image:
23+
name: Build and push images
24+
runs-on: ubuntu-latest
25+
strategy:
26+
fail-fast: false
27+
matrix:
28+
include:
29+
- file: ./docker/webapi/Dockerfile
30+
image: ${{ github.repository }}-webapi
31+
build-args: |
32+
33+
- file: ./docker/webapp/Dockerfile
34+
image: ${{ github.repository }}-webapp
35+
build-args: |
36+
37+
- file: ./docker/webapp/Dockerfile.nginx
38+
image: ${{ github.repository }}-webapp-nginx
39+
build-args: |
40+
REACT_APP_BACKEND_URI=${{ inputs.REACT_APP_BACKEND_URI }}
41+
REACT_APP_AAD_AUTHORITY=${{ inputs.REACT_APP_AAD_AUTHORITY }}
42+
REACT_APP_AAD_CLIENT_ID=${{ inputs.REACT_APP_AAD_CLIENT_ID }}
43+
REACT_APP_AAD_API_SCOPE=${{ inputs.REACT_APP_AAD_API_SCOPE }}
44+
permissions:
45+
contents: read
46+
packages: write
47+
48+
steps:
49+
- name: Checkout repository
50+
uses: actions/checkout@v3
51+
52+
- name: Login container registry
53+
uses: docker/login-action@v2
54+
with:
55+
registry: ${{ env.REGISTRY }}
56+
username: ${{ github.actor }}
57+
password: ${{ secrets.GITHUB_TOKEN }}
58+
59+
- name: Extract metadata (tags, labels)
60+
id: meta
61+
uses: docker/metadata-action@v4
62+
with:
63+
images: ${{ env.REGISTRY }}/${{ matrix.image }}
64+
tags: |
65+
type=ref,event=branch
66+
type=ref,event=pr
67+
type=semver,pattern={{version}}
68+
type=semver,pattern={{major}}
69+
type=semver,pattern={{major}}.{{minor}}
70+
71+
- name: Build and push image
72+
uses: docker/build-push-action@v3
73+
with:
74+
context: .
75+
file: ${{ matrix.file }}
76+
push: true
77+
tags: ${{ steps.meta.outputs.tags }}
78+
labels: ${{ steps.meta.outputs.labels }}
79+
build-args: ${{ matrix.build-args }}

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -489,4 +489,4 @@ webapi/CopilotChatWebApi.sln
489489
/deploy/
490490

491491
# Tesseract OCR language data files
492-
*.traineddata
492+
*.traineddata

docker/docker-compose.yaml

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
version: '3'
2+
services:
3+
chat-copilot-webapp:
4+
image: chat-copilot-webapp-nginx
5+
build:
6+
context: ..
7+
dockerfile: docker/webapp/Dockerfile
8+
ports:
9+
- 3000:3000
10+
env_file:
11+
- ../webapp/.env
12+
depends_on:
13+
chat-copilot-webapi:
14+
condition: service_started
15+
chat-copilot-webapi:
16+
image: chat-copilot-webapi
17+
build:
18+
context: ..
19+
dockerfile: docker/webapi/Dockerfile
20+
ports:
21+
- 8080:8080
22+
env_file:
23+
- ../webapi/.env
24+
environment:
25+
- MemoryStore__Qdrant__Host=http://qdrant
26+
depends_on:
27+
qdrant:
28+
condition: service_started
29+
qdrant:
30+
image: qdrant/qdrant
31+
ports:
32+
- 6333:6333
33+

docker/webapi/Dockerfile

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# docker build -f docker/webapi/Dockerfile -t chat-copilot-webapi .
2+
3+
# Learn about building .NET container images:
4+
# https://github.com/dotnet/dotnet-docker/blob/main/samples/README.md
5+
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
6+
WORKDIR /source
7+
8+
# generate dev-certs for https
9+
RUN dotnet dev-certs https
10+
11+
# copy csproj and restore as distinct layers
12+
COPY webapi/*.csproj .
13+
RUN dotnet restore --use-current-runtime
14+
15+
# copy everything else and build app
16+
COPY webapi/. .
17+
RUN apt update && apt install -y wget
18+
RUN wget -P data https://raw.githubusercontent.com/tesseract-ocr/tessdata/main/eng.traineddata
19+
RUN dotnet publish --use-current-runtime --self-contained false --no-restore -o /app
20+
21+
22+
# final stage/image
23+
FROM mcr.microsoft.com/dotnet/aspnet:6.0
24+
ENV Kestrel__Endpoints__Http__Url=http://0.0.0.0:8080
25+
WORKDIR /app
26+
COPY --from=build /app .
27+
COPY --from=build /root/.dotnet/corefx/cryptography/x509stores/my/* /root/.dotnet/corefx/cryptography/x509stores/my/
28+
29+
ENTRYPOINT ["./CopilotChatWebApi"]

docker/webapp/Dockerfile

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# docker build -f docker/webapp/Dockerfile -t chat-copilot-webapp .
2+
3+
# builder
4+
FROM node:lts-alpine as builder
5+
WORKDIR /app
6+
COPY webapp/ .
7+
RUN yarn install \
8+
--prefer-offline \
9+
--frozen-lockfile \
10+
--non-interactive \
11+
--production=false
12+
13+
# final stage/image
14+
FROM node:lts-alpine
15+
WORKDIR /app
16+
COPY --from=builder /app .
17+
ENV HOST 0.0.0.0
18+
EXPOSE 3000
19+
ENTRYPOINT [ "yarn", "start" ]

docker/webapp/Dockerfile.nginx

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# source webapp/.env
2+
# 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 .
3+
4+
# builder
5+
FROM node:lts-alpine as builder
6+
7+
ARG REACT_APP_BACKEND_URI
8+
ENV REACT_APP_BACKEND_URI $REACT_APP_BACKEND_URI
9+
10+
ARG REACT_APP_AAD_AUTHORITY
11+
ENV REACT_APP_AAD_AUTHORITY $REACT_APP_AAD_AUTHORITY
12+
13+
ARG REACT_APP_AAD_CLIENT_ID
14+
ENV REACT_APP_AAD_CLIENT_ID $REACT_APP_AAD_CLIENT_ID
15+
16+
ARG REACT_APP_AAD_API_SCOPE
17+
ENV REACT_APP_AAD_API_SCOPE $REACT_APP_AAD_API_SCOPE
18+
19+
WORKDIR /app
20+
COPY webapp/ .
21+
RUN yarn install \
22+
--prefer-offline \
23+
--frozen-lockfile \
24+
--non-interactive \
25+
--production=true
26+
27+
RUN yarn build
28+
29+
# final stage/image
30+
FROM nginx:stable-alpine
31+
EXPOSE 3000
32+
RUN sed -i 's/80/3000/g' /etc/nginx/conf.d/default.conf
33+
COPY --from=builder /app/build /usr/share/nginx/html
34+
CMD ["nginx", "-g", "daemon off;"]

0 commit comments

Comments
 (0)