Skip to content

Commit

Permalink
Add amd64 and arm64 build targets and precommit script
Browse files Browse the repository at this point in the history
Ensure both architectures are properly built and tested for CI compatibility. Introduced a precommit hook to streamline the process and made necessary amendments to the Dockerfile for ARM64 support.
  • Loading branch information
jorgecuesta committed Aug 6, 2024
1 parent 7f58039 commit a8b3b0e
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
14 changes: 11 additions & 3 deletions docker/node.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ ENV CHAIN_ID=$CHAIN_ID
# Add system dependencies
RUN apk update
RUN apk add git postgresql14-client tini curl jq
# The following was necessary to install in order to add support for building
# the docker container on an M1 chip (i.e. ARM64)
RUN apk add g++ make py3-pip
# add specific version of yq because depending on the operative system it could get another implementation or version
# than produce error on shell scripts later.
RUN curl -L https://github.com/mikefarah/yq/releases/download/v4.44.3/yq_linux_amd64 -o /usr/bin/yq &&\
Expand All @@ -68,9 +71,14 @@ COPY .yarn /home/app/.yarn
COPY scripts /home/app/scripts

# Install dependencies for production
# Starting from yarn 2.0, the --production flag is indeed deprecated.
# Yarn 2 introduced improvements to allow more precise installations.
RUN yarn workspaces focus --production
# NOTE: in case a yarn install fail, please add --inline-build to produce a more verbose installation logs, that could
# help you debugging what is going wrong.
RUN yarn install \
# Starting from yarn 2.0, the --production flag is indeed deprecated.
# Yarn 2 introduced improvements to allow more precise installations.
# The install now is needed because there are some dependencies that need to be build and that is achieve on install \
# the with this command the dependencies are reduced to only leave production one.
&& yarn workspaces focus --production

# Add the dependencies
COPY --from=builder /app/project.ts /app/schema.graphql /app/tsconfig.json /home/app/
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"scripts": {
"preinstall": "npx only-allow yarn",
"postinstall": "yarn run env:prepare",
"precommit": "./scripts/before-commit.sh",
"codegen": "yarn exec subql codegen",
"build": "./scripts/build.sh",
"watch:build": "./scripts/build.sh no-lint",
Expand Down
21 changes: 21 additions & 0 deletions scripts/before-commit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
### Added this script to allow locally build both version for amd64 and arm64 as a way to test it locally what will
### be done on CI.

### IMPORTANT: you should have `buildx` properly configured on your host.
### https://github.com/docker/buildx

set -e

. scripts/shared.sh

info_log "Building development for AMD64"
docker buildx build -f docker/dev-node.dockerfile -t pocket-network/pocketdex:development-amd64 --platform=linux/amd64 .

info_log "Building development for ARM64"
docker buildx build -f docker/dev-node.dockerfile -t pocket-network/pocketdex:development-arm64 --platform=linux/arm64 .

info_log "Building production for AMD64"
docker buildx build -f docker/node.dockerfile -t pocket-network/pocketdex:development-amd64 --platform=linux/amd64 .

info_log "Building production for ARM64"
docker buildx build -f docker/node.dockerfile -t pocket-network/pocketdex:development-arm64 --platform=linux/arm64 .

0 comments on commit a8b3b0e

Please sign in to comment.