diff --git a/.github/composite/build-image/action.yaml b/.github/composite/build-image/action.yaml index a718ac8d..b9221034 100644 --- a/.github/composite/build-image/action.yaml +++ b/.github/composite/build-image/action.yaml @@ -5,6 +5,10 @@ inputs: ENVIRONMENT: description: "'staging' or 'production'" required: true + ARCH: + description: "Target architecture to build natively (amd64 or arm64)." + required: false + default: amd64 outputs: tag: @@ -46,4 +50,4 @@ runs: - name: Run script id: build-image shell: bash - run: bun run .github/scripts/src/build-image --environment "${{ inputs.ENVIRONMENT }}" \ No newline at end of file + run: bun run .github/scripts/src/build-image --environment "${{ inputs.ENVIRONMENT }}" --arch="${{ inputs.ARCH }}" diff --git a/.github/composite/setup-ci/action.yaml b/.github/composite/setup-ci/action.yaml index dc0803d5..cf1254ae 100644 --- a/.github/composite/setup-ci/action.yaml +++ b/.github/composite/setup-ci/action.yaml @@ -19,7 +19,7 @@ runs: using: "composite" steps: - name: Setup - uses: tahminator/pipeline/actions/setup@1.0.73 + uses: tahminator/pipeline/actions/setup@07fc9d27be126e0e9905af56e5d1b74440592626 #1.0.89 with: INSTALL_SOPS: true SECRETS: ${{ inputs.SECRETS }} diff --git a/.github/scripts/src/build-image/index.ts b/.github/scripts/src/build-image/index.ts index 44d8d17d..af55fa4d 100644 --- a/.github/scripts/src/build-image/index.ts +++ b/.github/scripts/src/build-image/index.ts @@ -9,7 +9,7 @@ import { hideBin } from "yargs/helpers"; process.env.TZ = "America/New_York"; -const { environment, getGhaOutput, githubOutputFile, dockerFileName } = +const { environment, getGhaOutput, githubOutputFile, dockerFileName, arch } = await yargs(hideBin(process.argv)) .option("environment", { choices: ["staging", "production"] satisfies Environment[], @@ -32,9 +32,17 @@ const { environment, getGhaOutput, githubOutputFile, dockerFileName } = type: "string", default: "Dockerfile", }) + .option("arch", { + choices: ["amd64", "arm64"] as const, + describe: "Docker build architecture", + default: "amd64" as const, + }) .strict() .parse(); +const dockerRepository = arch === "arm64" ? "patchats-arm" : "patchats"; +const platforms = [`linux/${arch}`]; + async function main() { const DOCKER_HUB_PAT = process.env.DOCKER_HUB_PAT; @@ -66,10 +74,10 @@ async function main() { const gitSha = (await $`git rev-parse --short HEAD`.text()).trim(); await dockerClient.buildImage({ - dockerRepository: `patchats`, + dockerRepository, dockerFileLocation: `infra/${dockerFileName}`, tags: [`${tagPrefix}${timestamp}`, `${tagPrefix}${gitSha}`], - platforms: ["linux/amd64", "linux/arm64"], + platforms, }); if (getGhaOutput) { diff --git a/.github/scripts/src/update-tag/index.ts b/.github/scripts/src/update-tag/index.ts index 966d9fb7..ff07e5ea 100644 --- a/.github/scripts/src/update-tag/index.ts +++ b/.github/scripts/src/update-tag/index.ts @@ -40,7 +40,7 @@ async function main() { manifestRepo: ["Patina-Network", "k8s-manifests"], originRepo: ["Patina-Network", "patchats"], kustomizationFilePath: "base/production/patchats/kustomization.yaml", - imageName: "patinanetwork/patchats", + imageName: "patinanetwork/patchats-arm", newTag: gitSha, environment: "production", }); @@ -51,7 +51,7 @@ async function main() { manifestRepo: ["Patina-Network", "k8s-manifests"], originRepo: ["Patina-Network", "patchats"], kustomizationFilePath: "base/staging/patchats/kustomization.yaml", - imageName: "patinanetwork/patchats", + imageName: "patinanetwork/patchats-arm", newTag: `staging-${gitSha}`, environment: "staging", }); diff --git a/.github/workflows/deploy-production.yml b/.github/workflows/deploy-production.yml index 21480f0f..e2a1d941 100644 --- a/.github/workflows/deploy-production.yml +++ b/.github/workflows/deploy-production.yml @@ -109,7 +109,6 @@ jobs: shell: bash run: echo "skipping db test" - run-backend-instance: name: Test Run Backend Instance runs-on: ubuntu-latest @@ -123,10 +122,18 @@ jobs: uses: ./.github/composite/run-backend-instance build-image: - name: Build Docker Image & Upload to Registry - runs-on: ubuntu-latest + name: Build Docker Image & Upload to Registry (${{ matrix.arch }}) + runs-on: ${{ matrix.runner }} needs: [frontend-test, run-local-db, run-backend-instance] + strategy: + matrix: + include: + - arch: amd64 + runner: ubuntu-latest + - arch: arm64 + runner: ubuntu-24.04-arm + steps: - name: Checkout repository uses: actions/checkout@v6 @@ -143,6 +150,7 @@ jobs: uses: ./.github/composite/build-image with: ENVIRONMENT: production + ARCH: ${{ matrix.arch }} migrate-database: name: Migrate production database @@ -189,4 +197,4 @@ jobs: - name: Run Workflow uses: ./.github/composite/update-tag with: - ENVIRONMENT: production \ No newline at end of file + ENVIRONMENT: production diff --git a/.github/workflows/deploy-staging.yml b/.github/workflows/deploy-staging.yml index 7338e65f..b9f9e117 100644 --- a/.github/workflows/deploy-staging.yml +++ b/.github/workflows/deploy-staging.yml @@ -113,10 +113,18 @@ jobs: uses: ./.github/composite/run-backend-instance buildImage: - name: Build Docker Image & Upload to Registry - runs-on: ubuntu-latest + name: Build Docker Image & Upload to Registry (${{ matrix.arch }}) + runs-on: ${{ matrix.runner }} needs: [frontendTest, runLocalDb, runBackendInstance] + strategy: + matrix: + include: + - arch: amd64 + runner: ubuntu-latest + - arch: arm64 + runner: ubuntu-24.04-arm + steps: - name: Checkout repository uses: actions/checkout@v6 @@ -133,6 +141,7 @@ jobs: uses: ./.github/composite/build-image with: ENVIRONMENT: staging + ARCH: ${{ matrix.arch }} migrateDatabase: name: Migrate Staging Database