2024-10-03 05:11:05 +00:00
|
|
|
name: Build & Push Docker Images
|
2024-10-02 16:29:40 +00:00
|
|
|
|
|
|
|
on:
|
|
|
|
push:
|
|
|
|
branches:
|
2024-10-02 16:30:46 +00:00
|
|
|
- master
|
2024-10-02 16:29:40 +00:00
|
|
|
release:
|
|
|
|
types: [published]
|
|
|
|
|
|
|
|
jobs:
|
|
|
|
build-and-push:
|
|
|
|
runs-on: ubuntu-latest
|
2024-10-03 05:11:05 +00:00
|
|
|
strategy:
|
|
|
|
matrix:
|
|
|
|
service: [backend, app]
|
2024-10-02 16:29:40 +00:00
|
|
|
steps:
|
|
|
|
- name: Checkout code
|
|
|
|
uses: actions/checkout@v3
|
|
|
|
|
2024-10-18 11:56:02 +00:00
|
|
|
- name: Set up QEMU
|
|
|
|
uses: docker/setup-qemu-action@v2
|
|
|
|
|
2024-10-02 16:29:40 +00:00
|
|
|
- name: Set up Docker Buildx
|
|
|
|
uses: docker/setup-buildx-action@v2
|
2024-10-03 04:07:15 +00:00
|
|
|
with:
|
|
|
|
install: true
|
2024-10-02 16:29:40 +00:00
|
|
|
|
|
|
|
- name: Log in to DockerHub
|
|
|
|
uses: docker/login-action@v2
|
|
|
|
with:
|
|
|
|
username: ${{ secrets.DOCKER_USERNAME }}
|
|
|
|
password: ${{ secrets.DOCKER_PASSWORD }}
|
|
|
|
|
|
|
|
- name: Extract version from release tag
|
|
|
|
if: github.event_name == 'release'
|
|
|
|
id: version
|
|
|
|
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
|
|
|
|
|
2024-10-03 05:11:05 +00:00
|
|
|
- name: Build and push Docker image for ${{ matrix.service }}
|
2024-10-02 16:31:49 +00:00
|
|
|
if: github.ref == 'refs/heads/master' && github.event_name == 'push'
|
2024-10-02 16:29:40 +00:00
|
|
|
run: |
|
2024-10-03 04:07:15 +00:00
|
|
|
docker buildx create --use
|
2024-10-03 05:11:05 +00:00
|
|
|
if [[ "${{ matrix.service }}" == "backend" ]]; then \
|
|
|
|
DOCKERFILE=backend.dockerfile; \
|
|
|
|
IMAGE_NAME=perplexica-backend; \
|
|
|
|
else \
|
|
|
|
DOCKERFILE=app.dockerfile; \
|
|
|
|
IMAGE_NAME=perplexica-frontend; \
|
|
|
|
fi
|
|
|
|
docker buildx build --platform linux/amd64,linux/arm64 \
|
|
|
|
--cache-from=type=registry,ref=itzcrazykns1337/${IMAGE_NAME}:main \
|
|
|
|
--cache-to=type=inline \
|
|
|
|
-f $DOCKERFILE \
|
|
|
|
-t itzcrazykns1337/${IMAGE_NAME}:main \
|
|
|
|
--push .
|
2024-10-02 16:29:40 +00:00
|
|
|
|
2024-10-03 05:11:05 +00:00
|
|
|
- name: Build and push release Docker image for ${{ matrix.service }}
|
2024-10-02 16:29:40 +00:00
|
|
|
if: github.event_name == 'release'
|
|
|
|
run: |
|
2024-10-03 04:07:15 +00:00
|
|
|
docker buildx create --use
|
2024-10-03 05:11:05 +00:00
|
|
|
if [[ "${{ matrix.service }}" == "backend" ]]; then \
|
|
|
|
DOCKERFILE=backend.dockerfile; \
|
|
|
|
IMAGE_NAME=perplexica-backend; \
|
|
|
|
else \
|
|
|
|
DOCKERFILE=app.dockerfile; \
|
|
|
|
IMAGE_NAME=perplexica-frontend; \
|
|
|
|
fi
|
|
|
|
docker buildx build --platform linux/amd64,linux/arm64 \
|
|
|
|
--cache-from=type=registry,ref=itzcrazykns1337/${IMAGE_NAME}:${{ env.RELEASE_VERSION }} \
|
|
|
|
--cache-to=type=inline \
|
|
|
|
-f $DOCKERFILE \
|
|
|
|
-t itzcrazykns1337/${IMAGE_NAME}:${{ env.RELEASE_VERSION }} \
|
|
|
|
--push .
|