Skip to content

Commit 0484967

Browse files
committed
remove matrix and set condition in Dockerfile
1 parent 9f5b596 commit 0484967

File tree

4 files changed

+23
-32
lines changed

4 files changed

+23
-32
lines changed

.github/workflows/default__build-push-docker.yml

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@ jobs:
2222
build:
2323
name: Build and push docker image
2424
runs-on: ubuntu-latest
25-
strategy:
26-
matrix:
27-
platform: [linux/amd64, linux/arm64]
28-
2925
steps:
3026
- name: Checkout
3127
uses: actions/checkout@v4
@@ -46,7 +42,7 @@ jobs:
4642

4743
- name: Docker metadata
4844
# disable this step
49-
# if: false
45+
if: false
5046
id: metadata
5147
uses: docker/metadata-action@v5
5248
with:
@@ -58,43 +54,30 @@ jobs:
5854

5955
- name: Log in to Docker Hub
6056
uses: docker/login-action@v3
61-
# if: ${{ github.ref_type == 'tag' }}
6257
with:
6358
username: ${{ secrets.DOCKER_USERNAME }}
6459
password: ${{ secrets.DOCKER_PASSWORD }}
6560

66-
- name: Set environment variables for each architecture
67-
run: |
68-
if [[ "${{ matrix.platform }}" == "linux/amd64" ]]; then
69-
echo "SITE_URL=${{ env.SITE_URL_AMD64 }}" >> $GITHUB_ENV
70-
elif [[ "${{ matrix.platform }}" == "linux/arm64" ]]; then
71-
echo "SITE_URL=${{ env.SITE_URL_ARM64 }}" >> $GITHUB_ENV
72-
fi
73-
74-
# Must be in separate step to reflect
75-
- name: Debug assigned environment variable
76-
run: |
77-
echo "Debug: PLATFORM: ${{ matrix.platform }}, SITE_URL: ${{ env.SITE_URL }}"
78-
7961
- name: Build and push Docker image
8062
uses: docker/build-push-action@v6
8163
with:
8264
# src dir
8365
context: ./
8466
# Dockerfile dir
8567
file: ./docker/Dockerfile
86-
# platforms: linux/amd64,linux/arm64
87-
platforms: ${{ matrix.platform }}
68+
# cant use matrix, must pass platforms like this
69+
platforms: linux/amd64,linux/arm64
8870
build-args: |
89-
"ARG_SITE_URL=${{ env.SITE_URL }}"
71+
"ARG_SITE_URL_ARM64=${{ env.SITE_URL_ARM64 }}"
72+
"ARG_SITE_URL_AMD64=${{ env.SITE_URL_AMD64 }}"
9073
"ARG_PLAUSIBLE_SCRIPT_URL=${{ env.PLAUSIBLE_SCRIPT_URL }}"
9174
"ARG_PLAUSIBLE_DOMAIN=${{ env.PLAUSIBLE_DOMAIN }}"
9275
push: true
9376
tags: ${{ secrets.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}:latest
94-
cache-to: type=inline
77+
# cache-to: type=inline
78+
cache-from: type=registry,ref=${{ secrets.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}:buildcache
79+
cache-to: type=registry,ref=${{ secrets.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}:buildcache,mode=max
9580

9681
# disabled metadata step
9782
# tags: ${{ steps.metadata.outputs.tags }}
9883
# labels: ${{ steps.metadata.outputs.labels }}
99-
# cache-from: type=registry,ref=${{ secrets.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}:buildcache
100-
# cache-to: type=registry,ref=${{ secrets.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}:buildcache,mode=max

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ services:
1010
context: .
1111
dockerfile: ./docker/Dockerfile
1212
args:
13-
ARG_SITE_URL: 'http://localhost:8080'
13+
ARG_SITE_URL_AMD64: 'http://localhost:8080'
1414
# make separate script with localhost enabled
1515
ARG_PLAUSIBLE_SCRIPT_URL: 'https://plausible.arm1.nemanjamitic.com/js/script.js'
1616
# will trigger analytics

docker/Dockerfile

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,18 @@ RUN yarn add --ignore-engines [email protected]
2020

2121
COPY . .
2222

23-
# build time only env var
24-
ARG ARG_SITE_URL
25-
ENV SITE_URL=$ARG_SITE_URL
26-
RUN echo "SITE_URL=$SITE_URL"
23+
ARG ARG_SITE_URL_ARM64
24+
ARG ARG_SITE_URL_AMD64
25+
26+
# Set SITE_URL based on the target architecture
27+
# Docker provides TARGETARCH for this purpose
28+
ARG TARGETARCH
29+
RUN if [ "$TARGETARCH" = "arm64" ]; then \
30+
export SITE_URL=$ARG_SITE_URL_ARM64; \
31+
else \
32+
export SITE_URL=$ARG_SITE_URL_AMD64; \
33+
fi && \
34+
echo "SITE_URL=$SITE_URL"
2735

2836
ARG ARG_PLAUSIBLE_SCRIPT_URL
2937
ENV PLAUSIBLE_SCRIPT_URL=$ARG_PLAUSIBLE_SCRIPT_URL

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
"deploy:nginx:local": "bash scripts/deploy-nginx.sh '~/traefik-proxy/apps/nmc-nginx-with-volume/website' lxc11",
2020
"deploy:docker": "bash scripts/deploy-docker.sh arm1 '~/traefik-proxy/apps/nmc-docker' nemanjamitic/nemanjam.github.io",
2121
"deploy:docker:local": "bash scripts/deploy-docker.sh lxc11 '~/traefik-proxy/apps/nmc-docker' nemanjamitic/nemanjam.github.io",
22-
"docker:build:push:arm": "docker buildx build -f ./docker/Dockerfile -t nemanjamitic/nemanjam.github.io --build-arg ARG_SITE_URL='https://nmc-docker.arm1.nemanjamitic.com' --build-arg ARG_PLAUSIBLE_SCRIPT_URL='https://plausible.arm1.nemanjamitic.com/js/script.js' --build-arg ARG_PLAUSIBLE_DOMAIN='nemanjamitic.com' --platform linux/arm64 --push .",
23-
"docker:build:push:x86": "docker buildx build -f ./docker/Dockerfile -t nemanjamitic/nemanjam.github.io --build-arg ARG_SITE_URL='https://nmc-docker.local.nemanjamitic.com' --build-arg ARG_PLAUSIBLE_SCRIPT_URL='https://plausible.arm1.nemanjamitic.com/js/script.js' --build-arg ARG_PLAUSIBLE_DOMAIN='nemanjamitic.com' --platform linux/amd64 --push .",
22+
"docker:build:push:arm": "docker buildx build -f ./docker/Dockerfile -t nemanjamitic/nemanjam.github.io --build-arg ARG_SITE_URL_ARM64='https://nmc-docker.arm1.nemanjamitic.com' --build-arg ARG_PLAUSIBLE_SCRIPT_URL='https://plausible.arm1.nemanjamitic.com/js/script.js' --build-arg ARG_PLAUSIBLE_DOMAIN='nemanjamitic.com' --platform linux/arm64 --push .",
23+
"docker:build:push:x86": "docker buildx build -f ./docker/Dockerfile -t nemanjamitic/nemanjam.github.io --build-arg ARG_SITE_URL_AMD64='https://nmc-docker.local.nemanjamitic.com' --build-arg ARG_PLAUSIBLE_SCRIPT_URL='https://plausible.arm1.nemanjamitic.com/js/script.js' --build-arg ARG_PLAUSIBLE_DOMAIN='nemanjamitic.com' --platform linux/amd64 --push .",
2424
"docker:push": "docker push nemanjamitic/nemanjam.github.io",
2525
"dc:up": "docker compose up --build --force-recreate -d"
2626
},

0 commit comments

Comments
 (0)