Skip to content

Commit 2833269

Browse files
authored
Merge pull request #720 from NASA-AMMOS/jr-652
Added multi-platform build to support arm64 architecture
2 parents eb256c7 + 0ec71fe commit 2833269

File tree

3 files changed

+74
-22
lines changed

3 files changed

+74
-22
lines changed

.github/workflows/docker-build.yml

Lines changed: 54 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,20 @@ env:
3030
IMAGE_SLUG: ${{ github.repository }}
3131

3232
jobs:
33-
# Push image to GitHub Container Registry.
33+
# Generate shared tags for both architectures
3434
# The image tag pattern is:
3535
# for pull-requests: <PATCH_VERSION>-<DATE>-<PR_NUMBER>, eg: 1.35.2-20210125-25
3636
# for tags: <TAG>
3737
# for `master` branch: latest,<PATCH_VERSION>-latest,<MINOR_VERSION>-latest,<MAJOR_VERSION>-latest,<PATCH_VERSION>-<DATE>-<SHA>
3838
# for `development` branch: development,<MAJOR_VERSION>-development,<PATCH_VERSION>-<DATE>-<SHA>
3939
# for releases: release,<PATCH_VERSION>-release,<MINOR_VERSION>-release,<MAJOR_VERSION>-release,<PATCH_VERSION>-<DATE>-<SHA>
4040
# Version is parsed from package.json
41-
push:
41+
generate-tags:
4242
runs-on: ubuntu-latest
4343
if: github.event_name == 'push' || github.event_name == 'pull_request' || github.event_name == 'release'
44+
outputs:
45+
registry-tags: ${{ steps.generate.outputs.REGISTRY_TAGS }}
46+
image-id: ${{ steps.generate.outputs.IMAGE_ID }}
4447
steps:
4548
- name: Checkout
4649
uses: actions/checkout@v3
@@ -83,13 +86,13 @@ jobs:
8386
[ "$VERSION" == "development" ] && VERSION=development
8487
[ "${{ github.event_name }}" == "release" ] && VERSION=release
8588
86-
# Compose REGISTRY_TAGS variable
87-
REGISTRY_TAGS="-t $IMAGE_ID:$VERSION"
89+
# Compose REGISTRY_TAGS variable for buildx (space-separated with --tag flags)
90+
REGISTRY_TAGS="--tag $IMAGE_ID:$VERSION"
8891
8992
# For master branch also supply an extra tag: <PATCH_VERSION>-latest,<MINOR_VERSION>-latest,<MAJOR_VERSION>-latest,<PATCH_VERSION>-<DATE>-<SHA>
90-
[ "$VERSION" == "latest" ] && REGISTRY_TAGS="$REGISTRY_TAGS -t $IMAGE_ID:$PATCH_VERSION-latest -t $IMAGE_ID:$MINOR_VERSION-latest -t $IMAGE_ID:$MAJOR_VERSION-latest -t $IMAGE_ID:$PATCH_VERSION-$BDATE-$(git rev-parse --short HEAD)"
91-
[ "$VERSION" == "development" ] && REGISTRY_TAGS="$REGISTRY_TAGS -t $IMAGE_ID:$MAJOR_VERSION-development -t $IMAGE_ID:$PATCH_VERSION-$BDATE-$(git rev-parse --short HEAD)"
92-
[ "$VERSION" == "release" ] && REGISTRY_TAGS="$REGISTRY_TAGS -t $IMAGE_ID:$PATCH_VERSION-release -t $IMAGE_ID:$MINOR_VERSION-release -t $IMAGE_ID:$MAJOR_VERSION-release -t $IMAGE_ID:$PATCH_VERSION-$BDATE-$(git rev-parse --short HEAD)"
93+
[ "$VERSION" == "latest" ] && REGISTRY_TAGS="$REGISTRY_TAGS --tag $IMAGE_ID:$PATCH_VERSION-latest --tag $IMAGE_ID:$MINOR_VERSION-latest --tag $IMAGE_ID:$MAJOR_VERSION-latest --tag $IMAGE_ID:$PATCH_VERSION-$BDATE-$(git rev-parse --short HEAD)"
94+
[ "$VERSION" == "development" ] && REGISTRY_TAGS="$REGISTRY_TAGS --tag $IMAGE_ID:$MAJOR_VERSION-development --tag $IMAGE_ID:$PATCH_VERSION-$BDATE-$(git rev-parse --short HEAD)"
95+
[ "$VERSION" == "release" ] && REGISTRY_TAGS="$REGISTRY_TAGS --tag $IMAGE_ID:$PATCH_VERSION-release --tag $IMAGE_ID:$MINOR_VERSION-release --tag $IMAGE_ID:$MAJOR_VERSION-release --tag $IMAGE_ID:$PATCH_VERSION-$BDATE-$(git rev-parse --short HEAD)"
9396
9497
echo IMAGE_ID=$IMAGE_ID
9598
echo VERSION=$VERSION
@@ -99,19 +102,58 @@ jobs:
99102
SHA_SHORT=${{ github.sha }}
100103
[ "${{ github.event_name }}" == "pull_request" ] && SHA_SHORT=$(echo ${{ github.event.pull_request.head.sha }} | cut -c1-8)
101104
102-
echo "Final image tag to be pushed:"
105+
echo "Final image tags to be pushed:"
103106
echo $REGISTRY_TAGS
104107
echo "REGISTRY_TAGS=$REGISTRY_TAGS" >> $GITHUB_OUTPUT
105108
echo "IMAGE_ID=$IMAGE_ID" >> $GITHUB_OUTPUT
106109
echo "REGISTRY_TAGS_VERSION=$VERSION" >> $GITHUB_OUTPUT
107110
echo "REGISTRY_TAGS_PR_NUMBER=$PR_NUMBER" >> $GITHUB_OUTPUT
108111
echo "SHA_SHORT=$SHA_SHORT" >> $GITHUB_OUTPUT
109112
113+
# Build and push AMD64 image on x64 runner
114+
build-amd64:
115+
needs: generate-tags
116+
runs-on: ubuntu-latest # x64 runner for native AMD64 builds
117+
steps:
118+
- name: Checkout
119+
uses: actions/checkout@v3
120+
121+
- name: Set up Docker Buildx
122+
uses: docker/setup-buildx-action@v3
123+
110124
- name: Login to GHCR
111125
run: echo ${{ secrets.GITHUB_TOKEN }} | docker login -u ${{ github.actor }} --password-stdin ghcr.io
112126

113-
- name: Docker build
114-
run: docker build --no-cache ${{ steps.generate.outputs.REGISTRY_TAGS }} .
127+
- name: Docker buildx build and push (AMD64)
128+
run: |
129+
docker buildx build \
130+
--platform linux/amd64 \
131+
${{ needs.generate-tags.outputs.registry-tags }} \
132+
--push \
133+
--no-cache \
134+
.
135+
136+
# Build and push ARM64 image on ARM64 runner
137+
build-arm64:
138+
needs: generate-tags
139+
runs-on: ubuntu-24.04-arm # ARM64 runner for native ARM64 builds
140+
steps:
141+
- name: Checkout
142+
uses: actions/checkout@v3
115143

116-
- name: Docker push
117-
run: docker push ${{ steps.generate.outputs.IMAGE_ID }} --all-tags
144+
- name: Set up Docker Buildx
145+
uses: docker/setup-buildx-action@v3
146+
147+
- name: Login to GHCR
148+
run: echo ${{ secrets.GITHUB_TOKEN }} | docker login -u ${{ github.actor }} --password-stdin ghcr.io
149+
150+
- name: Docker buildx build and push (ARM64)
151+
run: |
152+
# Generate ARM64-specific tags by adding -arm64 suffix
153+
ARM64_TAGS="${{ needs.generate-tags.outputs.registry-tags }}-arm64"
154+
docker buildx build \
155+
--platform linux/arm64 \
156+
${ARM64_TAGS} \
157+
--push \
158+
--no-cache \
159+
.

Dockerfile

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,28 @@ WORKDIR /usr/src/app
1515
# Bundle app source
1616
COPY . .
1717

18-
1918
#############################
2019
# Python
2120
#############################
2221

23-
# micromamba
24-
RUN dnf install -y bzip2
22+
# Use build arguments to detect target platform (default to amd64 if not provided)
23+
ARG TARGETPLATFORM
24+
ARG TARGETARCH
25+
26+
# micromamba - Platform-specific download
27+
RUN dnf install -y bzip2 curl
2528
RUN mkdir -p /opt/micromamba/bin
26-
RUN curl -Ls https://micro.mamba.pm/api/micromamba/linux-64/latest | tar -C /opt/micromamba -xvj bin/micromamba
29+
30+
# Download correct micromamba binary based on architecture
31+
RUN MICROMAMBA_URL="https://micro.mamba.pm/api/micromamba/linux-64/latest" && \
32+
if [ "${TARGETARCH}" = "arm64" ]; then \
33+
MICROMAMBA_URL="https://micro.mamba.pm/api/micromamba/linux-aarch64/latest"; \
34+
elif [ -z "${TARGETARCH}" ]; then \
35+
echo "TARGETARCH is empty, defaulting to amd64"; \
36+
fi && \
37+
echo "Downloading micromamba for ${TARGETARCH} from: ${MICROMAMBA_URL}" && \
38+
curl -Ls "${MICROMAMBA_URL}" | tar -C /opt/micromamba -xvj bin/micromamba
39+
2740
RUN MAMBA_ROOT_PREFIX="/opt/micromamba"; /opt/micromamba/bin/micromamba shell init -s bash
2841
RUN echo 'export PATH="/opt/micromamba/bin:$PATH"' >> /root/.bashrc && echo 'export MAMBA_ROOT_PREFIX="/opt/micromamba"' >> /root/.bashrc
2942

@@ -35,7 +48,6 @@ RUN source ~/.bashrc && micromamba env create -y --name mmgis --file=python-envi
3548

3649
RUN dnf module install nodejs:20
3750

38-
3951
#############################
4052
# MMGIS
4153
#############################
@@ -45,7 +57,6 @@ RUN npm install
4557
# build
4658
RUN npm run build
4759

48-
4960
#############################
5061
# MMGIS Configure
5162
#############################
@@ -60,12 +71,8 @@ RUN npm install
6071
# Build Configure Site
6172
RUN npm run build
6273

63-
##
64-
6574
WORKDIR /usr/src/app/
6675

67-
#
68-
6976
RUN chmod 755 _docker-entrypoint.sh
7077

7178
EXPOSE 8888

python-environment.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ channels:
44
dependencies:
55
- python==3.12
66
- gdal==3.9.3
7+
- rasterio
8+
- geos
9+
- proj
710
- pip
811
- pip:
912
- numpy==2.1.0

0 commit comments

Comments
 (0)