Skip to content

Commit

Permalink
fix(infra): fix multiplatform build
Browse files Browse the repository at this point in the history
  • Loading branch information
Björn Urban committed Feb 22, 2024
1 parent 9d47dcc commit f36aa7f
Show file tree
Hide file tree
Showing 4 changed files with 172 additions and 141 deletions.
19 changes: 14 additions & 5 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,22 @@ jobs:
build:
runs-on: ubuntu-latest
environment: development
strategy:
matrix:
go-version: [ '1.21' ]
node-version: [ 18 ]
goarch: [ 'amd64', 'arm64' ] # Define architectures here
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Setup Go ${{ matrix.go-version }}
uses: actions/setup-go@v4
with:
go-version: '1.21'
go-version: ${{ matrix.go-version }}
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 18
node-version: ${{ matrix.node-version }}
- name: Cache node modules
uses: actions/cache@v3
with:
Expand All @@ -47,7 +52,8 @@ jobs:
run: go get ./...
- name: Build
working-directory: backend
run: GOOS=linux GOARCH=amd64 go build -o build/kubevoyage ./cmd/kubevoyage
run: |
GOOS=linux GOARCH=${{ matrix.goarch }} go build -o build/kubevoyage-${{ matrix.goarch }} ./cmd/kubevoyage
#- name: Test with the Go CLI
# run: go test
- name: Archive production artifacts
Expand All @@ -71,6 +77,7 @@ jobs:
uses: actions/download-artifact@v3
with:
name: production-artifacts

- name: Set up Docker Build
uses: docker/setup-buildx-action@v2

Expand All @@ -85,7 +92,9 @@ jobs:
context: .
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/kubevoyage:${{ env.BRANCH_NAME }}
platforms: linux/amd64,linux/arm64
platforms: linux/${{ matrix.goarch }}
build-args: |
TARGETARCH=${{ matrix.goarch }}
release:
needs: helm-release
runs-on: ubuntu-latest
Expand Down Expand Up @@ -140,4 +149,4 @@ jobs:
env:
registryImage: ${{ secrets.DOCKERHUB_USERNAME }}/kubevoyage
imageTag: ${{ github.head_ref || github.ref_name }}
CR_TOKEN: ${{ secrets.PAT }}
CR_TOKEN: ${{ secrets.PAT }}
143 changes: 76 additions & 67 deletions .github/workflows/release-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,74 +11,83 @@ env:
jobs:
build:
runs-on: ubuntu-latest
environment: development
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Setup Go ${{ matrix.go-version }}
uses: actions/setup-go@v4
with:
go-version: '1.21'
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 18
- name: Cache node modules
uses: actions/cache@v3
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install dependencies
working-directory: frontend
run: npm ci
- name: Build
working-directory: frontend
run: npm run build
- name: Install dependencies
working-directory: backend
run: go get ./...
- name: Build
working-directory: backend
run: GOOS=linux GOARCH=amd64 go build -o build/kubevoyage ./cmd/kubevoyage
#- name: Test with the Go CLI
# run: go test
- name: Archive production artifacts
uses: actions/upload-artifact@v3
with:
name: production-artifacts
path: |
backend/
frontend/public
build-docker:
needs: build
runs-on: ubuntu-latest
if: ${{ github.ref }} != 'master' && ${{ github.ref }} != 'development'
env:
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Download build artifact
uses: actions/download-artifact@v3
with:
name: production-artifacts
- name: Set up Docker Build
uses: docker/setup-buildx-action@v2
environment: production
strategy:
matrix:
go-version: [ '1.21' ]
node-version: [ 18 ]
goarch: [ 'amd64', 'arm64' ] # Define architectures here
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Setup Go ${{ matrix.go-version }}
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go-version }}
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- name: Cache node modules
uses: actions/cache@v3
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install dependencies
working-directory: frontend
run: npm ci
- name: Build
working-directory: frontend
run: npm run build
- name: Install dependencies
working-directory: backend
run: go get ./...
- name: Build
working-directory: backend
run: |
GOOS=linux GOARCH=${{ matrix.goarch }} go build -o build/kubevoyage-${{ matrix.goarch }} ./cmd/kubevoyage
#- name: Test with the Go CLI
# run: go test
- name: Archive production artifacts
uses: actions/upload-artifact@v3
with:
name: production-artifacts
path: |
backend/
frontend/public
build-docker:
needs: build
runs-on: ubuntu-latest
if: ${{ github.ref }} != 'master' && ${{ github.ref }} != 'development'
env:
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Download build artifact
uses: actions/download-artifact@v3
with:
name: production-artifacts

- name: Login to Docker Registry
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/kubevoyage:${{ env.BRANCH_NAME }}
platforms: linux/amd64,linux/arm64
- name: Set up Docker Build
uses: docker/setup-buildx-action@v2

- name: Login to Docker Registry
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/kubevoyage:${{ env.BRANCH_NAME }}
platforms: linux/${{ matrix.goarch }}
build-args: |
TARGETARCH=${{ matrix.goarch }}
helm-release:
needs: build-docker
# depending on default permission settings for your org (contents being read-only or read-write for workloads), you will have to add permissions
Expand Down
145 changes: 78 additions & 67 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,73 +12,84 @@ jobs:
build:
runs-on: ubuntu-latest
environment: development
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Setup Go ${{ matrix.go-version }}
uses: actions/setup-go@v4
with:
go-version: '1.21'
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 18
- name: Cache node modules
uses: actions/cache@v3
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install dependencies
working-directory: frontend
run: npm ci
- name: Build
working-directory: frontend
run: npm run build
- name: Install dependencies
working-directory: backend
run: go get ./...
- name: Build
working-directory: backend
run: GOOS=linux GOARCH=amd64 go build -o build/kubevoyage ./cmd/kubevoyage
#- name: Test with the Go CLI
# run: go test
- name: Archive production artifacts
uses: actions/upload-artifact@v3
with:
name: production-artifacts
path: |
backend/
frontend/public
build-docker:
needs: build
runs-on: ubuntu-latest
if: ${{ github.ref }} != 'master' && ${{ github.ref }} != 'development'
env:
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Download build artifact
uses: actions/download-artifact@v3
with:
name: production-artifacts
- name: Set up Docker Build
uses: docker/setup-buildx-action@v2
strategy:
matrix:
go-version: [ '1.21' ]
node-version: [ 18 ]
goarch: [ 'amd64', 'arm64' ] # Define architectures here
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Setup Go ${{ matrix.go-version }}
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go-version }}
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- name: Cache node modules
uses: actions/cache@v3
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install dependencies
working-directory: frontend
run: npm ci
- name: Build
working-directory: frontend
run: npm run build
- name: Install dependencies
working-directory: backend
run: go get ./...
- name: Build
working-directory: backend
run: |
GOOS=linux GOARCH=${{ matrix.goarch }} go build -o build/kubevoyage-${{ matrix.goarch }} ./cmd/kubevoyage
#- name: Test with the Go CLI
# run: go test
- name: Archive production artifacts
uses: actions/upload-artifact@v3
with:
name: production-artifacts
path: |
backend/
frontend/public
build-docker:
needs: build
runs-on: ubuntu-latest
if: ${{ github.ref }} != 'master' && ${{ github.ref }} != 'development'
env:
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Download build artifact
uses: actions/download-artifact@v3
with:
name: production-artifacts

- name: Set up Docker Build
uses: docker/setup-buildx-action@v2

- name: Login to Docker Registry
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/kubevoyage:${{ env.BRANCH_NAME }}
platforms: linux/${{ matrix.goarch }}
build-args: |
TARGETARCH=${{ matrix.goarch }}
- name: Login to Docker Registry
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/kubevoyage:${{ env.BRANCH_NAME }}
platforms: linux/amd64,linux/arm64
helm-release:
needs: build-docker
# depending on default permission settings for your org (contents being read-only or read-write for workloads), you will have to add permissions
Expand Down Expand Up @@ -110,4 +121,4 @@ jobs:
PULUMI_ACCESS_TOKEN: ${{ secrets.PULUMI_ACCESS_TOKEN }}
registryImage: ${{ secrets.DOCKERHUB_USERNAME }}/kubevoyage
imageTag: ${{ github.head_ref || github.ref_name }}
CR_TOKEN: ${{ secrets.PAT }}
CR_TOKEN: ${{ secrets.PAT }}
6 changes: 4 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
FROM golang:1.21

# Define an argument for the architecture, which will be passed from the build command
ARG TARGETARCH
LABEL authors="bjornurban"
EXPOSE 8080:8080

WORKDIR /kubevoyage

# Copy the correct binary based on the architecture argument
COPY backend/build/kubevoyage-${TARGETARCH} ./bin/kubevoyage
# Copy frontend and backend files
COPY frontend/public ./public
COPY backend/build ./bin
Expand Down

0 comments on commit f36aa7f

Please sign in to comment.