Skip to content

Commit 2ab4eac

Browse files
authored
Merge pull request #44 from ks6088ts-labs/feature/issue-43_docker-compose
support docker compose
2 parents 16523d1 + 7bfd58c commit 2ab4eac

File tree

4 files changed

+63
-49
lines changed

4 files changed

+63
-49
lines changed

Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ DOCKER_IMAGE_COMPONENT ?= backend
5555
DOCKER_COMMAND ?=
5656
DOCKER_TAG ?= $(DOCKER_IMAGE_COMPONENT)-$(GIT_TAG)
5757
DOCKER_FILE ?= ./dockerfiles/$(DOCKER_IMAGE_COMPONENT).Dockerfile
58+
DOCKER_COMPOSE_FILE ?= ./compose.yaml
5859

5960
# Tools
6061
TOOLS_DIR ?= $(HOME)/.local/bin
@@ -78,6 +79,10 @@ docker-run: ## run Docker container
7879
docker-lint: ## lint Dockerfile
7980
docker run --rm -i hadolint/hadolint < $(DOCKER_FILE)
8081

82+
.PHONY: docker-compose-lint
83+
docker-compose-lint: ## lint docker compose file
84+
docker compose --file $(DOCKER_COMPOSE_FILE) config --quiet
85+
8186
.PHONY: docker-scan
8287
docker-scan: ## scan Docker image
8388
@# https://aquasecurity.github.io/trivy/v0.18.3/installation/#install-script
@@ -88,7 +93,7 @@ docker-scan: ## scan Docker image
8893
_ci-test-docker: docker-lint docker-build docker-scan docker-run
8994

9095
.PHONY: ci-test-docker
91-
ci-test-docker: ## run CI test for Docker
96+
ci-test-docker: docker-compose-lint ## run CI test for Docker
9297
$(MAKE) _ci-test-docker DOCKER_IMAGE_COMPONENT=backend
9398
$(MAKE) _ci-test-docker DOCKER_IMAGE_COMPONENT=frontend
9499

README.md

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,21 @@ make ci-test-docker
4747

4848
## Deployment instructions
4949

50-
### Docker Hub
50+
### Docker compose
51+
52+
Docker compose is used to run the services locally.
53+
Refer to the following steps to run the services.
54+
See the actual implementation in the [compose.yaml](./compose.yaml) file.
55+
56+
```shell
57+
# Create environment files for each service
58+
cp {NAME}.env.sample {NAME}.env
59+
60+
# Build and run the services
61+
docker compose up
62+
```
63+
64+
### Push docker image to Docker Hub
5165

5266
To publish the docker image to Docker Hub via GitHub Actions, you need to set the following secrets in the repository.
5367

@@ -56,9 +70,17 @@ gh secret set DOCKERHUB_USERNAME --body $DOCKERHUB_USERNAME
5670
gh secret set DOCKERHUB_TOKEN --body $DOCKERHUB_TOKEN
5771
```
5872

59-
### Azure Functions
73+
### Deploy Azure Functions
74+
75+
To deploy the Azure Functions, run the following script.
6076

61-
To deploy the Azure Functions, you can refer to the following scripts.
77+
```shell
78+
# Deploy the Azure Functions
79+
sh ./scripts/deploy-azure-functions.sh
80+
81+
# Destroy the Azure Functions
82+
sh ./scripts/destroy-azure-functions.sh
83+
```
6284

6385
- [scripts/deploy-azure-functions.sh](./scripts/deploy-azure-functions.sh): Deploy the Azure Functions using Azure CLI.
6486
- [scripts/destroy-azure-functions.sh](./scripts/destroy-azure-functions.sh): Destroy the Azure Functions using Azure CLI.

compose.yaml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
services:
2+
backend:
3+
build:
4+
context: .
5+
dockerfile: dockerfiles/backend.Dockerfile
6+
image: ks6088ts/azure-ai-services-solutions:backend-latest
7+
command: python main.py backend --port 8888 --debug
8+
ports:
9+
- 8888:8888
10+
volumes:
11+
- ./azure_ai_document_intelligence.env:/app/azure_ai_document_intelligence.env
12+
- ./azure_ai_vision.env:/app/azure_ai_vision.env
13+
- ./azure_event_grid.env:/app/azure_event_grid.env
14+
- ./azure_openai.env:/app/azure_openai.env
15+
- ./azure_storage_blob.env:/app/azure_storage_blob.env
16+
- ./azure_storage_queue.env:/app/azure_storage_queue.env
17+
environment:
18+
- PYTHONUNBUFFERED=1
19+
frontend:
20+
build:
21+
context: .
22+
dockerfile: dockerfiles/frontend.Dockerfile
23+
image: ks6088ts/azure-ai-services-solutions:frontend-latest
24+
command: streamlit run main.py --server.port=8501 --server.address=0.0.0.0 -- frontend --solution-name sandbox --backend-url http://backend:8888 --debug
25+
ports:
26+
- 8501:8501
27+
volumes:
28+
- ./azure_ai_speech.env:/app/azure_ai_speech.env
29+
environment:
30+
- PYTHONUNBUFFERED=1

docs/README.md

Lines changed: 2 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,12 @@
1-
# How to run
2-
3-
## Docker
4-
5-
```shell
6-
# Build the Docker image (optional)
7-
make docker-build DOCKER_IMAGE_COMPONENT=backend GIT_TAG=latest
8-
make docker-build DOCKER_IMAGE_COMPONENT=frontend GIT_TAG=latest
9-
10-
# Create environment files for each service
11-
cp {NAME}.env.sample {NAME}.env
12-
13-
# Run the Docker container for the backend
14-
docker run --rm \
15-
--publish 8888:8888 \
16-
--volume ${PWD}/azure_ai_document_intelligence.env:/app/azure_ai_document_intelligence.env \
17-
--volume ${PWD}/azure_ai_vision.env:/app/azure_ai_vision.env \
18-
--volume ${PWD}/azure_event_grid.env:/app/azure_event_grid.env \
19-
--volume ${PWD}/azure_openai.env:/app/azure_openai.env \
20-
--volume ${PWD}/azure_storage_blob.env:/app/azure_storage_blob.env \
21-
--volume ${PWD}/azure_storage_queue.env:/app/azure_storage_queue.env \
22-
ks6088ts/azure-ai-services-solutions:backend-latest \
23-
python main.py backend \
24-
--port 8888 \
25-
--debug
26-
27-
# Access the backend: http://localhost:8888
28-
29-
# Run ngrok to expose the backend (for testing purposes only)
30-
ngrok http 8888
31-
NGROK_URL="<forwarding-url>"
32-
33-
# Run the Docker container for the frontend
34-
docker run --rm \
35-
--publish 8501:8501 \
36-
--volume ${PWD}/azure_ai_speech.env:/app/azure_ai_speech.env \
37-
ks6088ts/azure-ai-services-solutions:frontend-latest \
38-
streamlit run main.py --server.port=8501 --server.address=0.0.0.0 -- frontend \
39-
--solution-name sandbox \
40-
--backend-url ${NGROK_URL} \
41-
--debug
42-
43-
# Access the frontend: http://localhost:8501
44-
```
45-
461
# References
472

483
## Common
494

505
- [Typer](https://typer.tiangolo.com/#installation)
516
- [Kiota > Generate tailored Python and PHP API clients for any API with Kiota](https://devblogs.microsoft.com/microsoft365dev/generate-tailored-python-and-php-api-clients-for-any-api-with-kiota/)
527
- [How to exclude multiple directories in pre-commit](https://stackoverflow.com/a/75560858)
8+
- [Docker Compose Quickstart](https://docs.docker.com/compose/gettingstarted/)
9+
- [Validating docker-compose yml file](https://stackoverflow.com/a/40158753)
5310

5411
## Backend
5512

0 commit comments

Comments
 (0)