diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 5d4ac40..2b398ff 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -24,12 +24,11 @@ jobs: - name: Check if build and push is required run: if docker-compose pull ${{ matrix.service }}; then echo "SKIP=1" >> $GITHUB_ENV; else echo "SKIP=0" >> $GITHUB_ENV; fi - - name: Build container image - run: docker-compose build ${{ matrix.service }} - if: env.SKIP != 1 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 - - name: Push container image - run: docker-compose push ${{ matrix.service }} + - name: Build container image + run: docker buildx bake ${{ matrix.service }} --push if: env.SKIP != 1 - name: Dotenv Action diff --git a/backend/Dockerfile b/backend/Dockerfile index 32abd75..4d37860 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -1,15 +1,29 @@ -# https://hub.docker.com/alpine/git -FROM alpine/git as src +# https://hub.docker.com/_/debian/ +FROM --platform=$BUILDPLATFORM debian as src +RUN apt-get update && apt-get install -y git ARG GIT_HASH="master" WORKDIR /code RUN git clone https://github.com/nezhar/snypy-backend --single-branch --branch $GIT_HASH . # https://hub.docker.com/_/python -FROM python:3.10-slim +FROM python:3.12-slim COPY --from=src /code/snypy /usr/src/app/snypy COPY --from=src /code/requirements.txt /usr/src/app/snypy/requirements.txt WORKDIR /usr/src/app/snypy -RUN pip install --no-cache-dir pip gunicorn psycopg2-binary -U +RUN pip install --no-cache-dir pip gunicorn -U + +ARG TARGETPLATFORM +# run the command if it does not match arm/v7 +RUN if [ "$TARGETPLATFORM" != "linux/arm/v7" ]; then \ + pip install --no-cache-dir psycopg2-binary; \ + fi +# run the command if it matches arm/v7 +RUN if [ "$TARGETPLATFORM" = "linux/arm/v7" ]; then \ + apt-get update && apt-get install -y libpq-dev gcc && \ + pip install --no-cache-dir psycopg2; \ + apt-get remove -y gcc && apt-get autoremove -y; \ + fi + RUN pip install --no-cache-dir -r requirements.txt -EXPOSE 8000 \ No newline at end of file +EXPOSE 8000 diff --git a/backend/Dockerfile.dev b/backend/Dockerfile.dev index 4efdec4..ba23209 100644 --- a/backend/Dockerfile.dev +++ b/backend/Dockerfile.dev @@ -1,8 +1,8 @@ # https://hub.docker.com/_/python -FROM python:3.10-slim +FROM python:3.12-slim WORKDIR /usr/src/app/snypy COPY /code/snypy-backend/requirements.txt /usr/src/app/snypy/requirements.txt RUN pip install --no-cache-dir pip gunicorn psycopg2-binary -U RUN pip install --no-cache-dir -r requirements.txt -EXPOSE 8000 \ No newline at end of file +EXPOSE 8000 diff --git a/docker-compose.yml b/docker-compose.yml index 570064d..21dc66a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -18,7 +18,13 @@ services: build: context: ./backend/ args: - GIT_HASH: "${API_VERSION}" + GIT_HASH: master + x-bake: + platforms: + - linux/i386 + - linux/amd64 + - linux/arm/v7 + - linux/arm64 command: gunicorn --bind 0.0.0.0:8000 snypy.wsgi --log-level info environment: DEBUG: "False" @@ -40,13 +46,25 @@ services: build: context: ./static/ args: - GIT_HASH: "${API_VERSION}" + GIT_HASH: master + x-bake: + platforms: + - linux/i386 + - linux/amd64 + - linux/arm/v7 + - linux/arm64 ui: image: ${UI_REMOTE}:${UI_VERSION} build: context: ./frontend/ args: - GIT_HASH: "${UI_VERSION}" + GIT_HASH: master + x-bake: + platforms: + - linux/i386 + - linux/amd64 + - linux/arm/v7 + - linux/arm64 environment: REST_API_URL: "http://localhost:8000" diff --git a/frontend/Dockerfile b/frontend/Dockerfile index 8caaa84..380a3ae 100644 --- a/frontend/Dockerfile +++ b/frontend/Dockerfile @@ -1,5 +1,5 @@ # https://hub.docker.com/_/node -FROM node:16 AS build +FROM --platform=$BUILDPLATFORM node:16 AS build ARG GIT_HASH="master" WORKDIR /usr/src/app RUN apt-get update && apt-get install git -y @@ -9,7 +9,7 @@ RUN npm install RUN npm run build --prod # https://hub.docker.com/_/nginx -FROM nginx:1.21-alpine +FROM nginx:1.25-alpine COPY --from=build /usr/src/app/dist /usr/share/nginx/html COPY default.conf /etc/nginx/conf.d/default.conf COPY entrypoint.sh entrypoint.sh diff --git a/static/Dockerfile b/static/Dockerfile index d3867c5..5cc2f96 100644 --- a/static/Dockerfile +++ b/static/Dockerfile @@ -1,6 +1,5 @@ # https://hub.docker.com/_/python -FROM python:3.10-slim as build - +FROM --platform=$BUILDPLATFORM python:3.12-slim as build RUN apt-get update && apt-get install git -y ARG GIT_HASH="master" WORKDIR /usr/src/app @@ -20,7 +19,6 @@ ENV REGISTER_EMAIL_VERIFICATION_URL=static ENV CSRF_TRUSTED_ORIGINS=static RUN python manage.py collectstatic --noinput - # https://hub.docker.com/_/nginx -FROM nginx:1.21-alpine +FROM nginx:1.25-alpine COPY --from=build /static /usr/share/nginx/html