Skip to content

Commit

Permalink
feat: Cross-platform compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
kroese authored Nov 10, 2024
1 parent 8d7d880 commit 846169c
Showing 1 changed file with 22 additions and 17 deletions.
39 changes: 22 additions & 17 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
############################################################################################################
# Build the Go binary for the Gateway
############################################################################################################
FROM golang:1.21-alpine AS builder-casaos-gateway
FROM --platform=$BUILDPLATFORM golang:1.21-alpine AS builder-casaos-gateway

WORKDIR /app

Expand All @@ -18,7 +18,8 @@ COPY ./CasaOS-Gateway/service ./service
COPY ./CasaOS-Gateway/build ./build
COPY ./CasaOS-Gateway/main.go ./main.go

RUN go build -o casaos-gateway .
ARG TARGETOS TARGETARCH
RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH go build -a -installsuffix cgo -o casaos-gateway .

# default config
COPY ./CasaOS-Gateway/build/sysroot/etc/casaos/gateway.ini.sample /etc/casaos/gateway.ini
Expand All @@ -27,7 +28,7 @@ RUN mkdir -p /var/run/casaos/ && echo -n "{}" >> /var/run/casaos/routes.json
############################################################################################################
# Build the Go binary for the User Service
############################################################################################################
FROM golang:1.21-alpine AS builder-casaos-user-service
FROM --platform=$BUILDPLATFORM golang:1.21-alpine AS builder-casaos-user-service

WORKDIR /app

Expand All @@ -46,7 +47,6 @@ RUN mkdir -p codegen/message_bus && \
go run github.com/deepmap/oapi-codegen/cmd/[email protected] \
-package message_bus https://raw.githubusercontent.com/IceWhaleTech/CasaOS-MessageBus/main/api/message_bus/openapi.yaml > codegen/message_bus/api.go


COPY ./CasaOS-UserService/build ./build
COPY ./CasaOS-UserService/cmd ./cmd
COPY ./CasaOS-UserService/common ./common
Expand All @@ -56,15 +56,16 @@ COPY ./CasaOS-UserService/route ./route
COPY ./CasaOS-UserService/service ./service
COPY ./CasaOS-UserService/main.go ./main.go

RUN go build -o casaos-user-service .
ARG TARGETOS TARGETARCH
RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH go build -a -installsuffix cgo -o casaos-user-service .

# default config
COPY ./CasaOS-UserService/build/sysroot/etc/casaos/user-service.conf.sample /etc/casaos/user-service.conf

############################################################################################################
# Build the Go binary for the MessageBus
############################################################################################################
FROM golang:1.21-alpine AS builder-casaos-message-bus
FROM --platform=$BUILDPLATFORM golang:1.21-alpine AS builder-casaos-message-bus

WORKDIR /app

Expand All @@ -90,15 +91,16 @@ COPY ./CasaOS-MessageBus/route ./route
COPY ./CasaOS-MessageBus/service ./service
COPY ./CasaOS-MessageBus/main.go ./main.go

RUN go build -o casaos-message-bus .
ARG TARGETOS TARGETARCH
RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH go build -a -installsuffix cgo -o casaos-message-bus .

# default config
COPY ./CasaOS-MessageBus/build/sysroot/etc/casaos/message-bus.conf.sample /etc/casaos/message-bus.conf

############################################################################################################
# Build the Go binary for the AppManagement
############################################################################################################
FROM golang:1.21-alpine AS builder-casaos-app-management
FROM --platform=$BUILDPLATFORM golang:1.21-alpine AS builder-casaos-app-management

WORKDIR /app

Expand All @@ -117,7 +119,6 @@ RUN mkdir -p codegen/message_bus && \
go run github.com/deepmap/oapi-codegen/cmd/[email protected] \
-generate types,client -package message_bus https://raw.githubusercontent.com/IceWhaleTech/CasaOS-MessageBus/main/api/message_bus/openapi.yaml > codegen/message_bus/api.go


COPY ./CasaOS-AppManagement/build ./build
COPY ./CasaOS-AppManagement/service ./service
COPY ./CasaOS-AppManagement/route ./route
Expand All @@ -127,7 +128,8 @@ COPY ./CasaOS-AppManagement/common ./common
COPY ./CasaOS-AppManagement/cmd ./cmd
COPY ./CasaOS-AppManagement/main.go ./main.go

RUN go build -o casaos-app-management .
ARG TARGETOS TARGETARCH
RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH go build -a -installsuffix cgo -o casaos-app-management .

# default config
COPY ./CasaOS-AppManagement/build/sysroot/etc/casaos/app-management.conf.sample /etc/casaos/app-management.conf
Expand All @@ -136,7 +138,7 @@ COPY ./CasaOS-AppManagement/build/sysroot/etc/casaos/env /etc/casaos/env
############################################################################################################
# Build the Go binary for the LocalStorage
############################################################################################################
FROM golang:1.21-alpine AS builder-casaos-local-storage
FROM --platform=$BUILDPLATFORM golang:1.21-alpine AS builder-casaos-local-storage

WORKDIR /app

Expand Down Expand Up @@ -168,15 +170,16 @@ COPY ./CasaOS-LocalStorage/service ./service
COPY ./CasaOS-LocalStorage/main.go ./main.go
COPY ./CasaOS-LocalStorage/misc.go ./misc.go

RUN go build -o casaos-local-storage .
ARG TARGETOS TARGETARCH
RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH go build -a -installsuffix cgo -o casaos-local-storage .

# default config
COPY ./CasaOS-LocalStorage/build/sysroot/etc/casaos/local-storage.conf.sample /etc/casaos/local-storage.conf

############################################################################################################
# Build the Go binary for the UI
############################################################################################################
FROM node:16 AS builder-casaos-ui
FROM --platform=$BUILDPLATFORM node:16 AS builder-casaos-ui

ENV NODE_ENV=production

Expand All @@ -197,7 +200,7 @@ RUN yarn build
############################################################################################################
# Build the Go binary for the CasaOS Main
############################################################################################################
FROM golang:1.21-alpine AS builder-casaos-main
FROM --platform=$BUILDPLATFORM golang:1.21-alpine AS builder-casaos-main

WORKDIR /app

Expand Down Expand Up @@ -229,15 +232,16 @@ COPY ./CasaOS/service ./service
COPY ./CasaOS/types ./types
COPY ./CasaOS/main.go ./main.go

RUN go build -o casaos-main .
ARG TARGETOS TARGETARCH
RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH go build -a -installsuffix cgo -o casaos-main .

# default config
COPY ./CasaOS/build/sysroot/etc/casaos/casaos.conf.sample /etc/casaos/casaos.conf

############################################################################################################
# Build the Go binary for the CasaOS Cli
############################################################################################################
FROM golang:1.21-alpine AS builder-casaos-cli
FROM --platform=$BUILDPLATFORM golang:1.21-alpine AS builder-casaos-cli

WORKDIR /app

Expand Down Expand Up @@ -267,7 +271,8 @@ COPY ./CasaOS-CLI/build ./build
COPY ./CasaOS-CLI/cmd ./cmd
COPY ./CasaOS-CLI/main.go ./main.go

RUN go build -o casaos-cli .
ARG TARGETOS TARGETARCH
RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH go build -a -installsuffix cgo -o casaos-cli .

############################################################################################################
# Build the final image
Expand Down

0 comments on commit 846169c

Please sign in to comment.