Skip to content

Commit

Permalink
👷 Fix build bug
Browse files Browse the repository at this point in the history
  • Loading branch information
lleans committed Jul 28, 2024
1 parent 517a32f commit 6b7033c
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 44 deletions.
100 changes: 60 additions & 40 deletions .github/workflows/build-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,93 +8,113 @@ on:
release:
types:
- published
tags:
- 'v*.*.*'

env:
REGISTRY_IMAGE: ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_IMAGE }}
EVENT: ${{ github.event_name }}

jobs:
build-dev:
if: github.event_name == 'push'
build:
runs-on: ubuntu-latest
env:
DOCKER_IMAGE: ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_IMAGE }}

strategy:
fail-fast: false
matrix:
platform:
- linux/amd64
- linux/arm64
steps:
- name: Checkout to specific branch
- name: Checkout
uses: actions/checkout@v4
with:
ref: "fast-api"
ref: fast-api
sparse-checkout: |
MuslimProScrapper
- name: Prepare
run: |
platform=${{ matrix.platform }}
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.DOCKER_IMAGE }}
tags: |
type=raw,value=dev
images: ${{ env.REGISTRY_IMAGE }}

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to Docker Hub | Stable
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and push | dev
- name: Build and push by digest
id: build
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64,linux/arm64/v8
push: true
tags: ${{ steps.meta.outputs.tags }}
platforms: ${{ matrix.platform }}
labels: ${{ steps.meta.outputs.labels }}
outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true
build-args: |
INSTALL_BUILD_TOOLS=${{ matrix.platform == 'linux/arm64' && 'true' || 'false' }}
build-release:
if: github.event_name == 'release'
runs-on: ubuntu-latest
env:
DOCKER_IMAGE: ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_IMAGE }}
- name: Export digest
run: |
mkdir -p /tmp/digests
digest="${{ steps.build.outputs.digest }}"
touch "/tmp/digests/${digest#sha256:}"
- name: Upload digest
uses: actions/upload-artifact@v4
with:
name: digests-${{ env.PLATFORM_PAIR }}
path: /tmp/digests/*
if-no-files-found: error
retention-days: 1

merge:
runs-on: ubuntu-latest
needs:
- build
steps:
- name: Checkout to specific branch
uses: actions/checkout@v4
- name: Download digests
uses: actions/download-artifact@v4
with:
ref: "fast-api"
path: /tmp/digests
pattern: digests-*
merge-multiple: true

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.DOCKER_IMAGE }}
images: ${{ env.REGISTRY_IMAGE }}
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
${{ env.EVENT == 'release' && 'type=semver,pattern={{version}}\ntype=semver,pattern={{major}}.{{minor}}' || 'type=raw,value=dev' }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to Docker Hub | Stable
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and push | Stable
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64,linux/arm64/v8
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
INSTALL_BUILD_TOOLS=${{ matrix.platform == 'linux/arm64' && 'true' || 'false' }}
- name: Create manifest list and push
working-directory: /tmp/digests
run: |
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *)
- name: Inspect image and push
run: |
docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }}
8 changes: 4 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Stage 1: Build stage
FROM --platform=$BUILDPLATFORM python:3.12-alpine as builder
FROM python:3.12-alpine as builder

# Define build argument
ARG INSTALL_BUILD_TOOLS=false
Expand All @@ -16,10 +16,10 @@ COPY requirements.txt .

# Install Python dependencies
RUN pip install --upgrade pip && \
pip install --user -r requirements.txt
pip install --user -Ur requirements.txt --no-dependencies

# Stage 2: Runtime stage
FROM --platform=$BUILDPLATFORM python:3.12-alpine
FROM python:3.12-alpine

WORKDIR /app

Expand All @@ -30,4 +30,4 @@ COPY . .
# Update PATH to include pip-installed packages
ENV PATH=/root/.local/bin:$PATH

ENTRYPOINT ["python3", "router.py"]
CMD ["python", "router.py"]

0 comments on commit 6b7033c

Please sign in to comment.