Skip to content

Commit

Permalink
Merge pull request #50 from nleroy917/docker
Browse files Browse the repository at this point in the history
Dockerize user interface
  • Loading branch information
nleroy917 authored Feb 11, 2023
2 parents 8127e22 + 4a2e741 commit 8972f19
Show file tree
Hide file tree
Showing 12 changed files with 255 additions and 126 deletions.
11 changes: 11 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
web/
.env
.venv
venv
env
.vscode/
benchmarks/
R/
scripts/
sdk/
tests/
22 changes: 22 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
version: "3.8"

services:
server:
build:
context: .
dockerfile: Dockerfile
ports:
- 8000:8000

client:
build:
context: web/
dockerfile: Dockerfile
ports:
- 3000:3000
environment:
- NEXT_PUBLIC_API_URL=http://server:8000

networks:
optipyzer:
driver: bridge
3 changes: 1 addition & 2 deletions optipyzer/db/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from .models import Organism, AutocompleteOrganism, CodonUsage
from ..const import AA_CODON_LIBRARY


# not used unless the database connection
# is required at the endpoint level
def _get_db():
Expand Down Expand Up @@ -40,7 +41,6 @@ def calc_codon_usage(organism_id: int):

# Iterate through each amino acid in the library, and pull data for it
for aa in AA_CODON_LIBRARY:

# Pull data for that particular amino acid and its codon preferences
result = amino_acid_usage(organism_id, aa)

Expand Down Expand Up @@ -83,7 +83,6 @@ def amino_acid_usage(org_id: int, aa: str):
a particular amino acid.
"""
with SessionLocal() as db:

# get list of codons
codons = AA_CODON_LIBRARY[aa]

Expand Down
1 change: 0 additions & 1 deletion optipyzer/db/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ class AutocompleteOrganism(Base):


class CodonUsage(Base):

__tablename__ = "codon_usage"

org_id = Column(Integer, primary_key=True)
Expand Down
1 change: 1 addition & 0 deletions optipyzer/response_models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import Dict, List
from pydantic import BaseModel


# model for an optimization result
class OptimizationResult(BaseModel):
query: str
Expand Down
6 changes: 0 additions & 6 deletions scripts/load_autocomplete_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@


def reset_table(curs):

try:
# Drop table
query = """ DROP TABLE autocomplete_data """
Expand Down Expand Up @@ -58,7 +57,6 @@ def reset_table(curs):


def load_data(curs):

# Get unqique species from database
query = """SELECT * FROM ORGANISMS GROUP BY SPECIES"""
curs.execute(query)
Expand All @@ -70,7 +68,6 @@ def load_data(curs):
N = len(result)
i = 1
for row in result:

# Update user
print("Cleaned {}/{} rows".format(i, N))
i += 1
Expand Down Expand Up @@ -107,7 +104,6 @@ def load_data(curs):


def isolate_species(species_strain):

# Split on spaces
words = species_strain.split(" ")

Expand All @@ -121,7 +117,6 @@ def isolate_species(species_strain):


def connect_to_db(db_file):

# Attempt to connect to databse with specified file
try:
conn = sqlite3.connect(db_file)
Expand All @@ -134,7 +129,6 @@ def connect_to_db(db_file):


if __name__ == "__main__":

db_file = sys.argv[1]

if not db_file:
Expand Down
4 changes: 0 additions & 4 deletions sdk/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ def protein_seq():


def test_optimize_dna(api: optipyzer.API, dna_seq: str):

result = api.optimize(
seq=dna_seq,
seq_type="dna",
Expand All @@ -30,7 +29,6 @@ def test_optimize_dna(api: optipyzer.API, dna_seq: str):


def test_optimize_dna_with_pop_names(api: optipyzer.API, dna_seq: str):

result = api.optimize(
seq=dna_seq,
seq_type="dna",
Expand All @@ -42,7 +40,6 @@ def test_optimize_dna_with_pop_names(api: optipyzer.API, dna_seq: str):


def test_optimize_protein(api: optipyzer.API, protein_seq: str):

result = api.optimize(
seq=protein_seq,
seq_type="protein",
Expand All @@ -54,7 +51,6 @@ def test_optimize_protein(api: optipyzer.API, protein_seq: str):


def test_optimize_protein_with_pop_names(api: optipyzer.API, protein_seq: str):

result = api.optimize(
seq=protein_seq,
seq_type="protein",
Expand Down
8 changes: 8 additions & 0 deletions web/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Dockerfile
.dockerignore
node_modules
npm-debug.log
README.md
.next
.git
.env.local
59 changes: 59 additions & 0 deletions web/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
FROM node:18-alpine AS base

# Install dependencies only when needed
FROM base AS deps
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
RUN apk add --no-cache libc6-compat
WORKDIR /app

# Install dependencies based on the preferred package manager
COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./
RUN \
if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
elif [ -f package-lock.json ]; then npm ci; \
elif [ -f pnpm-lock.yaml ]; then yarn global add pnpm && pnpm i --frozen-lockfile; \
else echo "Lockfile not found." && exit 1; \
fi


# Rebuild the source code only when needed
FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .

# Next.js collects completely anonymous telemetry data about general usage.
# Learn more here: https://nextjs.org/telemetry
# Uncomment the following line in case you want to disable telemetry during the build.
# ENV NEXT_TELEMETRY_DISABLED 1

RUN yarn build

# If using npm comment out above and use below instead
# RUN npm run build

# Production image, copy all the files and run next
FROM base AS runner
WORKDIR /app

ENV NODE_ENV production
# Uncomment the following line in case you want to disable telemetry during runtime.
# ENV NEXT_TELEMETRY_DISABLED 1

RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs

COPY --from=builder /app/public ./public

# Automatically leverage output traces to reduce image size
# https://nextjs.org/docs/advanced-features/output-file-tracing
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static

USER nextjs

EXPOSE 3000

ENV PORT 3000

CMD ["node", "server.js"]
1 change: 1 addition & 0 deletions web/next.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module.exports = {
output: 'standalone',
eslint: {
dirs: ['src'],
},
Expand Down
9 changes: 4 additions & 5 deletions web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
"prettier:check": "prettier -c src",
"format": "prettier -w src",
"release": "standard-version",
"push-release": "git push --follow-tags origin main",
"postbuild": "next-sitemap"
"push-release": "git push --follow-tags origin main"
},
"dependencies": {
"@headlessui/react": "^1.6.5",
Expand All @@ -26,10 +25,10 @@
"axios": "^0.23.0",
"clsx": "^1.1.1",
"debounce-promise": "^3.1.2",
"next": "^12.1.0",
"next": "latest",
"postcss": "^8.3.9",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-hook-form": "^7.17.4",
"react-icons": "^4.3.1",
"react-select": "^5.1.0"
Expand Down
Loading

1 comment on commit 8972f19

@vercel
Copy link

@vercel vercel bot commented on 8972f19 Feb 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.