Build both platforms in one action

This commit is contained in:
Aaron Reisman 2024-10-22 03:45:44 -05:00 committed by Aaron Reisman
parent 011efe3676
commit 9825e2b552
3 changed files with 19 additions and 23 deletions

View File

@ -23,15 +23,7 @@ on:
jobs: jobs:
build_and_push: build_and_push:
runs-on: ubuntu-latest runs-on: ubuntu-latest
strategy:
# Prevent a failure in one image from stopping the other builds
fail-fast: false
matrix:
os:
- ubuntu-latest
arch:
- amd64
- arm64
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v4 uses: actions/checkout@v4
@ -43,6 +35,7 @@ jobs:
uses: docker/setup-buildx-action@v3 uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub - name: Login to Docker Hub
if: ${{ inputs.release }}
uses: docker/login-action@v3 uses: docker/login-action@v3
with: with:
username: ${{ secrets.docker_username }} username: ${{ secrets.docker_username }}
@ -62,11 +55,9 @@ jobs:
- name: Build and push image - name: Build and push image
uses: docker/build-push-action@v6 uses: docker/build-push-action@v6
with: with:
platforms: ${{ matrix.arch }} platforms: linux/amd64,linux/arm64
push: ${{ steps.metadata.outputs.tags != ''}} push: ${{ steps.metadata.outputs.tags != ''}}
cache-from: type=gha cache-from: type=gha
cache-to: type=gha,mode=max cache-to: type=gha,mode=max
tags: ${{ steps.metadata.outputs.tags }} tags: ${{ steps.metadata.outputs.tags }}
labels: ${{ steps.metadata.outputs.labels }} labels: ${{ steps.metadata.outputs.labels }}
build-args: |
TARGETARCH=${{ matrix.arch }}

View File

@ -49,17 +49,22 @@ update_settings() {
is_mounted() { is_mounted() {
DIR=$1 DIR=$1
return $(mount | grep ${DIR}) if mount | grep -q "${DIR}";
then
return 0
else
return 1
fi
} }
create_db() { create_db() {
FILE=$1 DBFILE=$1
if [ -f "${FILE}" ]; then if [ -f "${DBFILE}" ]; then
warn "prexisting database found when creating" warn "prexisting database found when creating"
return 0 return 0
else else
warn "database not found, creating one at ${FILE}" warn "database not found, creating one at ${DBFILE}"
if ! touch "${FILE}"; then if ! touch "${DBFILE}"; then
error "unable to create database, check permissions on host" error "unable to create database, check permissions on host"
exit 1 exit 1
fi fi
@ -93,9 +98,9 @@ main() {
info "loading database" info "loading database"
FILE=LibationContext.db FILE=LibationContext.db
# If user provides a separate database mount, use that # If user provides a separate database mount, use that
if [ is_mounted ${LIBATION_DB_DIR} ]; if is_mounted ${LIBATION_DB_DIR};
then then
debug using database directory `${LIBATION_DB_DIR}` debug "using database directory ${LIBATION_DB_DIR}"
if [ -f "${LIBATION_DB_DIR}/${FILE}" ]; then if [ -f "${LIBATION_DB_DIR}/${FILE}" ]; then
info "database found in ${LIBATION_DB_DIR}" info "database found in ${LIBATION_DB_DIR}"
else else
@ -104,7 +109,7 @@ main() {
ln -s /${LIBATION_DB_DIR}/${FILE} ${LIBATION_CONFIG_INTERNAL}/${FILE} ln -s /${LIBATION_DB_DIR}/${FILE} ${LIBATION_CONFIG_INTERNAL}/${FILE}
# Otherwise, use the config directory # Otherwise, use the config directory
else else
debug using config directory `${LIBATION_CONFIG_DIR}` debug "using config directory ${LIBATION_CONFIG_DIR}"
if [ -f "${LIBATION_CONFIG_DIR}/${FILE}" ]; then if [ -f "${LIBATION_CONFIG_DIR}/${FILE}" ]; then
info "database found in ${LIBATION_CONFIG_DIR}" info "database found in ${LIBATION_CONFIG_DIR}"
else else
@ -114,7 +119,7 @@ main() {
fi fi
# Try to warn if books dir wasn't mounted in # Try to warn if books dir wasn't mounted in
if [ ! is_mounted ${LIBATION_BOOKS_DIR} ]; if ! is_mounted ${LIBATION_BOOKS_DIR};
then then
warn "${LIBATION_BOOKS_DIR} does not appear to be mounted, books will not be saved" warn "${LIBATION_BOOKS_DIR} does not appear to be mounted, books will not be saved"
fi fi

View File

@ -1,6 +1,6 @@
# Dockerfile # Dockerfile
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0 AS build FROM --platform=${BUILDPLATFORM} mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG TARGETARCH=amd64 ARG TARGETARCH
COPY Source /Source COPY Source /Source
RUN dotnet publish \ RUN dotnet publish \