Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
atrakic committed Nov 19, 2023
1 parent 0426a52 commit d0c938d
Show file tree
Hide file tree
Showing 17 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/docker-build-model.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ on:
- 'main'
# only build when important files change
paths:
- 'model/**'
- 'src/model/**'
- '.github/workflows/call-docker-build-model.yaml'
pull_request:
branches:
- 'main'
# only build when important files change
paths:
- 'model/**'
- 'src/model/**'
- '.github/workflows/call-docker-build-model.yaml'

env:
Expand Down
7 changes: 2 additions & 5 deletions .github/workflows/docker-build-web.yaml
Original file line number Diff line number Diff line change
@@ -1,28 +1,25 @@
name: Build Web
# template source: https://github.com/dockersamples/.github/blob/main/templates/call-docker-build.yaml

on:
# we want pull requests so we can build(test) but not push to image registry
push:
branches:
- 'main'
# only build when important files change
paths:
- 'frontend/**'
- 'src/frontend/**'
- '.github/workflows/call-docker-build-web.yaml'
pull_request:
branches:
- 'main'
# only build when important files change
paths:
- 'frontend/**'
- 'src/frontend/**'
- '.github/workflows/call-docker-build-web.yaml'

jobs:
call-docker-build:

name: Web Call Docker Build

uses: dockersamples/.github/.github/workflows/reusable-docker-build.yaml@main

permissions:
Expand Down
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
MAKEFLAGS += --silent

BASEDIR=$(shell git rev-parse --show-toplevel)

APP ?= web

.PHONY: test healthcheck clean
Expand All @@ -17,7 +19,7 @@ healthcheck:
docker inspect $(APP) --format "{{ (index (.State.Health.Log) 0).Output }}"

clean:
rm -rf model/*.pkl *.pkl
rm -rf ${BASEDIR}/src/model/*.pkl *.pkl
docker-compose down --volumes --remove-orphans -v

-include include.mk
6 changes: 3 additions & 3 deletions compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: '3'
services:
web:
build:
context: frontend
context: src/frontend
container_name: web
environment:
- PORT=5000
Expand All @@ -24,7 +24,7 @@ services:
start_period: 3s
model:
build:
context: model
context: src/model
command:
- /prices.csv
container_name: model
Expand All @@ -35,7 +35,7 @@ services:
- MODEL_FILE=/data/model.pkl
test:
build:
context: test-client
context: src/client
container_name: test
environment:
- API_URL=http://web:5000/api
Expand Down
5 changes: 2 additions & 3 deletions healthchecks/ping.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@
import argparse
import socket
import urllib.request
from datetime import datetime

parser = argparse.ArgumentParser()
parser.add_argument("url", type=str, help="Url to ping.")


def main(args):
try:
with urllib.request.urlopen(args.url, timeout=10) as _:
print(datetime.now())
with urllib.request.urlopen(args.url, timeout=10) as res:
print(res.read())
except socket.error as error_:
print(f"Ping failed: {error_}")

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 2 additions & 1 deletion frontend/Dockerfile → src/frontend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
FROM python:3.11-slim-buster
LABEL org.opencontainers.image.description="Flask API with ML prediction"
LABEL maintainer="Admir Trakic <[email protected]>"

# Keeps Python from generating .pyc files in the container
ENV PYTHONDONTWRITEBYTECODE=1
Expand All @@ -11,7 +12,7 @@ COPY requirements.txt .
RUN python -m pip install -r requirements.txt

WORKDIR /app
COPY ./src .
COPY . .

RUN adduser -u 5678 --disabled-password --gecos "" appuser && chown -R appuser /app
USER appuser
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions model/Dockerfile → src/model/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ RUN /venv/bin/pip install --disable-pip-version-check -r /requirements.txt

FROM gcr.io/distroless/python3-debian11 as final
LABEL org.opencontainers.image.description="Machine Learning model to predict house prices"
LABEL maintainer="Admir Trakic <[email protected]>"
COPY --from=build-venv /venv /venv
WORKDIR /app
COPY . .
Expand Down
File renamed without changes.
File renamed without changes.

0 comments on commit d0c938d

Please sign in to comment.