Skip to content

Commit

Permalink
Update build workflow to support multiple platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
nezhar committed May 24, 2024
1 parent ba16d6c commit 6f5cf8b
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 21 deletions.
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 libpq-dev 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

0 comments on commit 6f5cf8b

Please sign in to comment.