ilk etapta verdiğim adreste zaten dockerfile bulunduğu için kendi oluşturduğum dosyayı eklememe gerek duymamıştım (halen de duymuyorum) ama sorun olursa diye ekleyeyim:
##########
# BUILDER #
###########
# pull official base image
FROM python:3.8-alpine as builder
# set work directory
WORKDIR /usr/src/app
# set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
# install psycopg2 dependencies
RUN apk update \
&& apk add icu-data-full\
&& apk add --no-cache curl gpg gnupg\
&& apk add --no-cache postgresql-dev gcc libc-dev g++ libffi-dev libxml2 python3-dev musl-dev unixodbc unixodbc-dev mariadb-dev
# lint
RUN pip install --upgrade pip
RUN pip install flake8==5.0
COPY . .
RUN flake8 --ignore=E501,F401,F403 .
# install dependencies
RUN pip install --upgrade pip
COPY ./requirements.txt .
RUN pip wheel --no-cache-dir --no-deps --wheel-dir /usr/src/app/wheels -r requirements.txt
RUN pip install --extra-index-url https://alpine-wheels.github.io/index\
numpy==1.23 pandas==1.4.4 psycopg2-binary==2.9.3 pyodbc==4.0.34
# RUN pip install --extra-index-url https://alpine-wheels.github.io/index\
# numpy pandas psycopg2-binary pyodbc
#########
# FINAL #
#########
# pull official base image
FROM python:3.9.6-alpine
# create directory for the app user
RUN mkdir -p /home/app
# create the app user
RUN addgroup -S app && adduser -S app -G app
# create the appropriate directories
ENV HOME=/home/app
ENV APP_HOME=/home/app/web
RUN mkdir $APP_HOME
WORKDIR $APP_HOME
# install dependencies
RUN apk update && apk add libpq
COPY --from=builder /usr/src/app/wheels /wheels
COPY --from=builder /usr/src/app/requirements.txt .
RUN pip install --no-cache /wheels/*
# copy entrypoint.prod.sh
COPY ./entrypoint.prod.sh .
RUN sed -i 's/\r$//g' $APP_HOME/entrypoint.prod.sh
RUN chmod +x $APP_HOME/entrypoint.prod.sh
# copy project
COPY . $APP_HOME
# chown all the files to the app user
RUN chown -R app:app $APP_HOME
# change to the app user
USER app
# run entrypoint.prod.sh
ENTRYPOINT ["/home/app/web/entrypoint.prod.sh"]
docker-compose.prod.yml dosyası içeriği:
version: '3.7'
services:
backend:
build:
context: ./backend
dockerfile: Dockerfile.prod
container_name: backend
command: gunicorn common.wsgi:application --bind 0.0.0.0:8000
restart: 'no'
ports:
- 8000:8000
env_file:
- ./.env.prod
depends_on:
- db
frontend:
build: ./frontend
container_name: frontend
command: npm run serve
restart: 'no'
ports:
- 8080:8080
env_file:
- ./.env.dev
depends_on:
- backend
db:
image: postgres:13.0-alpine
container_name: database
restart: 'no'
volumes:
- postgres_data:/var/lib/postgresql/data/
env_file:
- ./.env.prod.db
volumes:
postgres_data:
ek soru: üstteki dockerfile ve yaml kodlarını nasıl okunur hale getirebiliriz?
Şurada da yine kalabalık etmesin diye ilk etapta vermediğim hata bulunuyor:
...
Step 24/31 : RUN pip install --no-cache /wheels/*
---> Running in f7ab30e42a91
Processing /wheels/Django-3.2-py3-none-any.whl
Processing /wheels/asgiref-3.5.2-py3-none-any.whl
Processing /wheels/django_cors_headers-3.13.0-py3-none-any.whl
Processing /wheels/djangorestframework-3.13.1-py3-none-any.whl
Processing /wheels/mssql_django-1.1.3-py3-none-any.whl
Processing /wheels/python_dateutil-2.8.2-py2.py3-none-any.whl
Processing /wheels/pytz-2022.2.1-py2.py3-none-any.whl
Processing /wheels/six-1.16.0-py2.py3-none-any.whl
Processing /wheels/sqlparse-0.4.2-py3-none-any.whl
Collecting pyodbc>=3.0
Downloading pyodbc-4.0.34.tar.gz (271 kB)
Building wheels for collected packages: pyodbc
Building wheel for pyodbc (setup.py): started
Building wheel for pyodbc (setup.py): finished with status 'error'
ERROR: Command errored out with exit status 1:
command: /usr/local/bin/python -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-esaumu8o/pyodbc_2efe275bbf104ec6856821129a5d62f1/setup.py'"'"'; __file__='"'"'/tmp/pip-install-esaumu8o/pyodbc_2efe275bbf104ec6856821129a5d62f1/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-2231biya
cwd: /tmp/pip-install-esaumu8o/pyodbc_2efe275bbf104ec6856821129a5d62f1/
Complete output (9 lines):
running bdist_wheel
running build
running build_ext
building 'pyodbc' extension
creating build
creating build/temp.linux-x86_64-3.9
creating build/temp.linux-x86_64-3.9/src
gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -DTHREAD_STACK_SIZE=0x100000 -fPIC -DPYODBC_VERSION=4.0.34 -I/usr/local/include/python3.9 -c src/buffer.cpp -o build/temp.linux-x86_64-3.9/src/buffer.o -Wno-write-strings
error: command 'gcc' failed: No such file or directory
----------------------------------------
ERROR: Failed building wheel for pyodbc
Running setup.py clean for pyodbc
Failed to build pyodbc
Installing collected packages: sqlparse, pytz, asgiref, six, pyodbc, Django, python-dateutil, mssql-django, djangorestframework, django-cors-headers
Running setup.py install for pyodbc: started
Running setup.py install for pyodbc: finished with status 'error'
ERROR: Command errored out with exit status 1:
command: /usr/local/bin/python -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-esaumu8o/pyodbc_2efe275bbf104ec6856821129a5d62f1/setup.py'"'"'; __file__='"'"'/tmp/pip-install-esaumu8o/pyodbc_2efe275bbf104ec6856821129a5d62f1/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-s2xueds6/install-record.txt --single-version-externally-managed --compile --install-headers /usr/local/include/python3.9/pyodbc
cwd: /tmp/pip-install-esaumu8o/pyodbc_2efe275bbf104ec6856821129a5d62f1/
Complete output (9 lines):
running install
running build
running build_ext
building 'pyodbc' extension
creating build
creating build/temp.linux-x86_64-3.9
creating build/temp.linux-x86_64-3.9/src
gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -DTHREAD_STACK_SIZE=0x100000 -fPIC -DPYODBC_VERSION=4.0.34 -I/usr/local/include/python3.9 -c src/buffer.cpp -o build/temp.linux-x86_64-3.9/src/buffer.o -Wno-write-strings
error: command 'gcc' failed: No such file or directory
----------------------------------------
ERROR: Command errored out with exit status 1: /usr/local/bin/python -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-esaumu8o/pyodbc_2efe275bbf104ec6856821129a5d62f1/setup.py'"'"'; __file__='"'"'/tmp/pip-install-esaumu8o/pyodbc_2efe275bbf104ec6856821129a5d62f1/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-s2xueds6/install-record.txt --single-version-externally-managed --compile --install-headers /usr/local/include/python3.9/pyodbc Check the logs for full command output.
WARNING: You are using pip version 21.2.4; however, version 22.3 is available.
You should consider upgrading via the '/usr/local/bin/python -m pip install --upgrade pip' command.
ERROR: Service 'backend' failed to build: The command '/bin/sh -c pip install --no-cache /wheels/*' returned a non-zero code: 1