Skip to content

Instantly share code, notes, and snippets.

@alongubkin
Last active June 7, 2021 23:23
Show Gist options
  • Save alongubkin/ec6fed94ab5f0306e0447e7f935d8f34 to your computer and use it in GitHub Desktop.
Save alongubkin/ec6fed94ab5f0306e0447e7f935d8f34 to your computer and use it in GitHub Desktop.
Dockerfile + Makefile + GitHub Action
name: Deploy
on:
push:
branches:
- main
jobs:
deploy:
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@master
- name: Install dependencies
run: make install-deps
working-directory: ./my_model
- name: Deploy
run: make deploy
working-directory: ./my_model
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_ECR_ACCOUNT_URL: ${{ secrets.AWS_ECR_ACCOUNT_URL }}
AWS_REGION: us-west-2
PULUMI_ACCESS_TOKEN: ${{ secrets.PULUMI_ACCESS_TOKEN }}
FROM python:3.8-slim
WORKDIR /my_model
STOPSIGNAL SIGINT
ENV LISTEN_PORT 80
# System dependencies
RUN apt update && apt install -y libgomp1
RUN pip3 install poetry
# Project dependencies
COPY poetry.lock pyproject.toml ./
RUN poetry config virtualenvs.create false
RUN poetry install --no-interaction --no-ansi --no-dev
COPY . .
WORKDIR /my_model/src
ENTRYPOINT uvicorn my_model.serving.__main__:app --host 0.0.0.0 --port $LISTEN_PORT --workers 2
SHELL := /bin/bash
STACK_NAME=dev
BASE_STACK_NAME=alongubkin/ml-infra/dev
PULUMI_CMD=pulumi --non-interactive --stack $(STACK_NAME) --cwd infra/
install-deps:
curl -fsSL https://get.pulumi.com | sh
npm install -C infra/
sudo pip3 install poetry --upgrade
poetry install
train:
poetry run train
deploy:
$(PULUMI_CMD) stack init $(STACK_NAME) || true
$(PULUMI_CMD) config set aws:region $(AWS_REGION)
$(PULUMI_CMD) config set baseStackName $(BASE_STACK_NAME)
$(PULUMI_CMD) config set runID $(shell poetry run train | awk '/Run ID/{print $$NF}')
$(PULUMI_CMD) up --yes --skip-preview
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment