Skip to content
Open
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
1 change: 1 addition & 0 deletions mlops/annotation_app/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
GOOGLE_APPLICATION_CREDENTIAL="google-storage-service-account.json"
5 changes: 5 additions & 0 deletions mlops/annotation_app/.gcloudignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# cloudbuild/内に置いた方が良さそうだが、今はこの位置の.gcludignoreのみ認識してくれる
.gitignore
*.json
*.env*
.venv/
42 changes: 28 additions & 14 deletions mlops/annotation_app/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,35 @@
# ベースイメージとしてPythonの公式イメージを使用
FROM python:3.9-slim
FROM python:3.10.2-buster

# 作業ディレクトリを設定
WORKDIR /app
USER root
EXPOSE 8080

# 必要なファイルをコンテナ内にコピー
COPY requirements.txt requirements.txt
COPY main.py main.py
COPY app.yaml app.yaml
COPY google-storage-service-account.json google-storage-service-account.json
COPY templates/ templates/
RUN apt-get update && apt-get upgrade -y
RUN apt-get -y install locales && \
localedef -f UTF-8 -i ja_JP ja_JP.UTF-8
ENV LANG ja_JP.UTF-8
ENV LANGUAGE ja_JP:ja
ENV LC_ALL ja_JP.UTF-8
ENV TZ JST-9
ENV TERM xterm

ARG POETRY_HOME="/opt/poetry"
ARG POETRY_VERSION="1.6.1"

RUN mkdir -p /root/app
COPY ./ /root/app
WORKDIR /root/app

# Pythonパッケージをインストール
RUN pip install --no-cache-dir -r requirements.txt
RUN curl -sSL https://install.python-poetry.org/ | python3 - --version ${POETRY_VERSION} && \
ln -s ${POETRY_HOME}/bin/poetry /usr/local/bin/poetry && \
poetry config virtualenvs.create false

# 必要なファイルをコンテナ内にコピー
RUN mkdir -p /root/app
COPY ./ /root/app
WORKDIR /root/app

# 環境変数を設定
ENV GOOGLE_APPLICATION_CREDENTIALS="/app/google-storage-service-account.json"
RUN poetry install --no-root --no-ansi

# アプリケーションを実行
CMD ["python", "main.py"]
# CMD ["python", "main.py"]
22 changes: 22 additions & 0 deletions mlops/annotation_app/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
### dockerに入る
```
docker compose up -d
```
```
docker exec -it annotation-app bash
```

### poetry
```
poetry install
```

### 実行
```
poetry run python3 src/main.py
```

### デプロイ
```
cd cloudbuild && sh cloudbuild.sh
```
31 changes: 31 additions & 0 deletions mlops/annotation_app/cloudbuild/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# ベースイメージとしてPythonの公式イメージを使用
FROM python:3.10.2-buster

USER root
EXPOSE 8080

RUN apt-get update && apt-get upgrade -y
RUN apt-get -y install locales && \
localedef -f UTF-8 -i ja_JP ja_JP.UTF-8
ENV LANG ja_JP.UTF-8
ENV LANGUAGE ja_JP:ja
ENV LC_ALL ja_JP.UTF-8
ENV TZ JST-9
ENV TERM xterm

ARG POETRY_HOME="/opt/poetry"
ARG POETRY_VERSION="1.6.1"

RUN mkdir -p /root/app
COPY ./ /root/app
WORKDIR /root/app

RUN curl -sSL https://install.python-poetry.org/ | python3 - --version ${POETRY_VERSION} && \
ln -s ${POETRY_HOME}/bin/poetry /usr/local/bin/poetry && \
poetry config virtualenvs.create false


RUN poetry install --no-root --no-ansi

# アプリケーションを実行
CMD ["poetry", "run", "python3", "src/main.py"]
4 changes: 4 additions & 0 deletions mlops/annotation_app/cloudbuild/cloudbuild.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
REGION="us-central1"
PROJECT_ID="camera-app-391105"

gcloud builds submit --region=${REGION} --project=${PROJECT_ID} --config=cloudbuild.yaml ../
44 changes: 44 additions & 0 deletions mlops/annotation_app/cloudbuild/cloudbuild.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
steps:
# (1) コンテナイメージのビルドを実行
- name: "gcr.io/cloud-builders/docker"
args:
[
"build",
"-t",
"${LOCATION}-docker.pkg.dev/$PROJECT_ID/${_DOCKER_NAME}/main:latest",
"-f",
"./cloudbuild/Dockerfile",
".",
]

# (2) ビルドしたコンテナイメージをArtifact Registryにプッシュ
- name: "gcr.io/cloud-builders/docker"
args:
[
"push",
"$LOCATION-docker.pkg.dev/$PROJECT_ID/${_DOCKER_NAME}/main:latest",
]

# (3) Cloud Runにデプロイ
- name: "gcr.io/cloud-builders/gcloud"
args:
- "run"
- "deploy"
- "${_RUN_SERVICE_NAME}"
- "--image"
- "$LOCATION-docker.pkg.dev/$PROJECT_ID/${_DOCKER_NAME}/main:latest"
- "--platform"
- "managed"
- "--region"
- "$LOCATION"
- "--allow-unauthenticated"
- "--service-account"
- "${_SERVICE_ACCOUNT_FOR_RUN}"

options:
logging: CLOUD_LOGGING_ONLY

substitutions:
_DOCKER_NAME: "annotation-app"
_RUN_SERVICE_NAME: "annotation-app"
_SERVICE_ACCOUNT_FOR_RUN: "sa-run-backend-dev"
16 changes: 16 additions & 0 deletions mlops/annotation_app/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
version: "3.3"

services:
annotation-app:
build:
context: ./
dockerfile: Dockerfile
container_name: annotation-app
tty: true
ports:
- 127.0.0.1:8080:8080
restart: always
volumes:
- ./:/root/app/
env_file:
- .env
Loading