Skip to content

Commit

Permalink
python: Initial implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
misodengaku committed Nov 22, 2023
1 parent a9691de commit d8fb77e
Show file tree
Hide file tree
Showing 7 changed files with 2,474 additions and 0 deletions.
88 changes: 88 additions & 0 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
name: Python CI
on:
push:
branches: [main]
paths:
- bench/**/*
- webapp/python/**/*
- webapp/sql/**/*
- webapp/pdns/**/*
- development/docker-compose-common.yml
- development/docker-compose-python.yml
- development/Makefile
- .github/workflows/python.yml
pull_request:
paths:
- bench/**/*
- webapp/python/**/*
- webapp/sql/**/*
- webapp/pdns/**/*
- development/docker-compose-common.yml
- development/docker-compose-python.yml
- development/Makefile
- .github/workflows/python.yml
workflow_dispatch:
jobs:
test:
strategy:
matrix:
go:
- 1.21.1
name: Build
runs-on: [isucon13-ci-06]
steps:
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go }}
id: go

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20

- name: Setup corepack
run: corepack enable yarn

# to avoid error: Deleting the contents of '/home/ubuntu/actions-runner/_work/isucon13/isucon13'
# Error: File was unable to be removed Error: EACCES: permission denied, rmdir
# https://github.com/actions/checkout/issues/211
- name: chown workdir
run: sudo chown -R $USER:$USER $GITHUB_WORKSPACE

- name: Check out code into the Go module directory
uses: actions/checkout@v3

# containers
- name: "setup containers"
working-directory: ./development
run: |
make down/python
make up/python
- name: "[frontend] build"
working-directory: ./frontend
run: |
make
# bench
- name: "[bench] Get deps"
working-directory: ./bench
env:
TZ: Asia/Tokyo
run: |
go get -v -t -d ./...
- name: "[bench] Test"
working-directory: ./bench
env:
TZ: Asia/Tokyo
run: |
go clean -testcache
go test -p=1 -v ./...
- name: "run bench"
working-directory: ./bench
run: |
make bench
27 changes: 27 additions & 0 deletions development/docker-compose-python.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
version: "3.0"

services:
webapp:
cpus: 2
mem_limit: 4g
build:
context: ../webapp/python
init: true
working_dir: /home/isucon/webapp/python
container_name: webapp
volumes:
- ../webapp/sql:/home/isucon/webapp/sql
- ../webapp/pdns:/home/isucon/webapp/pdns
- ../provisioning/ansible/roles/powerdns/files/pdns.conf:/etc/powerdns/pdns.conf:ro
- ../provisioning/ansible/roles/powerdns/files/pdns.d/docker.conf:/etc/powerdns/pdns.d/docker.conf:ro
- ../webapp/img:/home/isucon/webapp/img
environment:
ISUCON13_MYSQL_DIALCONFIG_ADDRESS: mysql
ISUCON13_POWERDNS_HOST: powerdns
ISUCON13_POWERDNS_SUBDOMAIN_ADDRESS: 127.0.0.1
ISUCON13_POWERDNS_DISABLED: false
ports:
- "127.0.0.1:8080:8080"
depends_on:
mysql:
condition: service_healthy
33 changes: 33 additions & 0 deletions webapp/python/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
FROM python:3.12-bookworm

WORKDIR /tmp
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && \
apt-get -y upgrade && \
apt-get install -y curl wget gcc g++ make sqlite3 locales locales-all && \
wget -q https://dev.mysql.com/get/mysql-apt-config_0.8.22-1_all.deb && \
apt-get -y install ./mysql-apt-config_0.8.22-1_all.deb && \
apt-get -y update && \
apt-get -y install default-mysql-client pdns-server pdns-backend-mysql && \
pip install pipenv
RUN locale-gen en_US.UTF-8
RUN useradd --uid=1001 --create-home isucon
USER isucon

RUN mkdir -p /home/isucon/webapp/python
WORKDIR /home/isucon/webapp/python
COPY --chown=isucon:isucon Pipfile /home/isucon/webapp/python/
COPY --chown=isucon:isucon Pipfile.lock /home/isucon/webapp/python/
RUN pipenv install
COPY --chown=isucon:isucon models.py /home/isucon/webapp/python/
COPY --chown=isucon:isucon app.py /home/isucon/webapp/python/

# ENV GOPATH=/home/isucon/tmp/go
# ENV GOCACHE=/home/isucon/tmp/go/.cache

ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8

EXPOSE 8080
CMD ["pipenv", "run", "python", "app.py"]
20 changes: 20 additions & 0 deletions webapp/python/Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]
flask = "*"
pymysql = "*"
bcrypt = "*"
sqlalchemy = "<2.0.0"
mysql-connector-python = "*"

[dev-packages]
flake8 = "*"
isort = "*"
black = "*"

[requires]
python_version = "3.12"
python_full_version = "3.12.0"
Loading

0 comments on commit d8fb77e

Please sign in to comment.