Skip to content

Instantly share code, notes, and snippets.

@exchgr
Last active March 16, 2023 15:04
Show Gist options
  • Save exchgr/0fd441994297b5119e20bbcffc8aa4e8 to your computer and use it in GitHub Desktop.
Save exchgr/0fd441994297b5119e20bbcffc8aa4e8 to your computer and use it in GitHub Desktop.
containerized native yarn berry cross-compilation from amd64 on github actions to arm64 for use on aws ecr and eks running graviton nodes
FROM --platform=$BUILDPLATFORM node:18-alpine AS builder
WORKDIR /app
ENV NODE_ENV=production
RUN apk add build-base
ARG TARGETARCH
ENV npm_config_arch=$TARGETARCH
COPY yarn.lock .
COPY .yarn .yarn
COPY package.json .
COPY package-lock.json .
COPY .yarnrc.yml .
COPY tsconfig.json .
RUN yarn set version berry
RUN yarn
COPY . .
RUN yarn build
FROM --platform=$TARGETPLATFORM node:18-alpine
WORKDIR /app
COPY --from=builder /app .
CMD ["yarn", "start"]
name: your-workflow-name
jobs:
build-and-push-image:
runs-on: ubuntu-latest
env:
IMAGE_TAG: ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com/${{ secrets.ECR_REPOSITORY }}
steps:
- name: "checkout"
uses: actions/checkout@v3
- name: "authenticate with aws"
uses: aws-actions/configure-aws-credentials@v2
with:
aws-region: ${{ secrets.AWS_REGION }}
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
- name: "log into ecr"
uses: aws-actions/amazon-ecr-login@v1
- name: "set up qemu"
uses: docker/setup-qemu-action@v2
with:
platforms: 'arm64'
- name: "set up buildx"
uses: docker/setup-buildx-action@v2
- name: "build and push"
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: ${{ env.IMAGE_TAG }}:latest
cache-from: type=registry,ref=${{ env.IMAGE_TAG }}:latest
cache-to: type=inline
platforms: linux/arm64
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment