Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update build workflow to support multiple platforms #30

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 19 additions & 5 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
EXPOSE 8000
4 changes: 2 additions & 2 deletions backend/Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -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
EXPOSE 8000
24 changes: 21 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
4 changes: 2 additions & 2 deletions frontend/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
6 changes: 2 additions & 4 deletions static/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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