Skip to content

Commit

Permalink
Fix docker build
Browse files Browse the repository at this point in the history
  • Loading branch information
Yasamato committed Apr 14, 2021
1 parent fa98b82 commit 40d1dcb
Show file tree
Hide file tree
Showing 12 changed files with 30 additions and 217 deletions.
43 changes: 0 additions & 43 deletions .dockerignore

This file was deleted.

1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -27,6 +27,7 @@
.pub-cache/
.pub/
/build/
.pubspec.lock

# Environments
.env
Expand Down
26 changes: 17 additions & 9 deletions Dockerfile
Expand Up @@ -3,9 +3,16 @@
# ------------------------------------------------------------------------------
FROM cirrusci/flutter:2.0.4 as flutter-build

# Copy as few files as possible to take advantage of build caching
# and as this is a build image, they number of layers don't matter
WORKDIR /app
COPY . .
COPY lib/ lib/
COPY web/ web/
COPY test/ test/
COPY .metadata .
COPY pubspec.yaml .

# build the web app
RUN flutter build web

# ------------------------------------------------------------------------------
Expand All @@ -29,22 +36,23 @@ LABEL org.opencontainers.image.vendor="/r/animepiracy" \
org.opencontainers.image.title="Index" \
maintainer="Community of /r/animepiracy"

# install nginx
# copy python requirements beforehand for improved building caching
COPY api/requirements.txt .

# install nginx and needed python packages
RUN apt-get update -y && \
apt-get install --no-install-recommends -y nginx makepasswd wget && \
apt-get autoremove -y && \
rm -rf /var/lib/apt/lists/*

# install needed python packages
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
rm -rf /var/lib/apt/lists/* && \
pip install --no-cache-dir -r requirements.txt

# replace default nginx conf
COPY nginx.conf /etc/nginx/conf.d/default.conf
# copy build web app
COPY --from=flutter-build /app/build/web /usr/share/nginx/html

WORKDIR /app
COPY api /app
COPY --from=flutter-build /app/build/web /usr/share/nginx/html
COPY api .

# sed is for replacing windows newline
CMD sed -i 's/\r$//' start.sh && sh start.sh
6 changes: 3 additions & 3 deletions api/init.py
Expand Up @@ -144,9 +144,9 @@ def transfer_table(data, table):


if __name__ == "__main__":
with open(os.path.join('../static', 'columns.json')) as json_file:
with open(os.path.join('static', 'columns.json')) as json_file:
columns_data = json.load(json_file)
with open(os.path.join('../static', 'tables.json')) as json_file:
with open(os.path.join('static', 'tables.json')) as json_file:
tables_data = json.load(json_file)

with create_app().app_context():
Expand Down Expand Up @@ -198,7 +198,7 @@ def transfer_table(data, table):
for c in TableColumn.query.all():
print(c.to_dict())

with open(os.path.join("../static", "data.json"), encoding="utf8") as json_file:
with open(os.path.join("static", "data.json"), encoding="utf8") as json_file:
old_data = json.load(json_file)

# streaming sites
Expand Down
15 changes: 8 additions & 7 deletions api/mutations.py
@@ -1,6 +1,5 @@
import json
import logging

from flask import Blueprint, request, current_app
from flask_discord import requires_authorization

Expand Down Expand Up @@ -318,12 +317,14 @@ def create_table_column(table_id):
if not data:
return "received no POST JSON data", 403

t = Table.query.get(table_id)
if t is None:
return "table %s not found" % table_id, 403
c = Column.query.get(data["column_id"])
if c is None:
return "column %s not found" % data["column_id"], 403
t = Table.query.get_or_404(
table_id,
"table %s not found" % table_id
)
c = Column.query.get_or_404(
data["column_id"],
"column %s not found" % data["column_id"]
)
insert = TableColumn(table_id=t.id, column_id=c.id, order=data["order"], hidden=data["hidden"])

user = current_app.discord.fetch_user()
Expand Down
File renamed without changes.
1 change: 0 additions & 1 deletion start.sh → api/start.sh
Expand Up @@ -14,7 +14,6 @@ sed -i "s/sponsoredAnime/${sponsored_anime}/g" /app/static/js/sponsored.js
sed -i "s/sponsoredAnime/${sponsored_anime}/g" /app/index.html

mkdir -p /config
cd /app/api || return

# migrate if db does not exists
if [ ! -f /config/data.db ]; then
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion nginx.conf
Expand Up @@ -19,7 +19,7 @@ server {


location / {
root /app;
root /usr/share/nginx/html;
}

location /api {
Expand Down
153 changes: 0 additions & 153 deletions pubspec.lock

This file was deleted.

0 comments on commit 40d1dcb

Please sign in to comment.