Skip to content

Commit

Permalink
Build image for raspberry pis
Browse files Browse the repository at this point in the history
  • Loading branch information
Dinika committed Apr 28, 2024
1 parent 9d74bb6 commit a95989b
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 5 deletions.
37 changes: 37 additions & 0 deletions Dockerfile.prod
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
FROM docker.io/arm64v8/python:3-slim as builder

RUN pip install poetry

ENV POETRY_NO_INTERACTION=1 \
POETRY_VIRTUALENVS_IN_PROJECT=1 \
POETRY_VIRTUALENVS_CREATE=1 \
POETRY_CACHE_DIR=/tmp/expenses-cache

WORKDIR /app

COPY src/pyproject.toml src/poetry.lock ./

RUN --mount=type=cache,target=$POETRY_CACHE_DIR poetry install --without dev --no-root

FROM docker.io/arm64v8/python:3-slim as runtime

ENV VIRTUAL_ENV=/app/.venv \
PATH="/app/.venv/bin:$PATH"


COPY --from=builder ${VIRTUAL_ENV} ${VIRTUAL_ENV}
WORKDIR /app


COPY ./src/expenses_server /app/expenses_server
COPY ./src/alembic /app/alembic
COPY ./src/alembic.ini /app/
COPY ./src/static /app/static

COPY ./docker-entrypoint.sh /app/

ENV FRONTEND_PATH=/app/static

EXPOSE 8000

ENTRYPOINT ["./docker-entrypoint.sh"]
24 changes: 19 additions & 5 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ function help() {
Path to the directory containing the backend server code.
Example:
./build.sh ../expenses-react ../expenses_server_fastapi x86
# For personal laptops (usually x86 architecture)
./build.sh ../expenses-react ../expenses_server_fastapi x86_64
# or the following to build the image for the raspberry pi
./build.sh ../expenses-react ../expenses_server_fastapi arm64v8
EOH
}

Expand All @@ -52,7 +56,14 @@ function main() {
fi
local fe_path="${1:?No frontend path passed}"
local be_path="${2:?No backend path passed}"
local arch="${3:-}"
local env="${3:-}"
if [[ "$env" == "prod" ]]; then
arch="arm64v8"
dockerfile="./Dockerfile.prod"
else
arch="x86_64"
dockerfile="./Dockerfile"
fi

if $do_build; then
cleanup
Expand All @@ -64,16 +75,19 @@ function main() {
copyFrontend "$fe_path" "src/static"
fi

buildContainer "$arch"
buildContainer "$arch" "$dockerfile"

}

function buildContainer() {
local arch="${1:-}"
docker build \
local dockerfile="${2:-}"

podman build \
--tag "expenses-app:dev-latest" \
--arch "${arch}" \
-f "${dockerfile}" \
.
# ${arch:+--arch=$arch} \
}

function cleanup() {
Expand Down

0 comments on commit a95989b

Please sign in to comment.