@@ -54,102 +54,85 @@ jobs:
5454 - name : Run tests
5555 run : make test
5656
57- build-matrix :
58- name : Build Binaries
59- runs-on : ubuntu-latest
60- needs : test
61- if : github.event_name == 'push' || github.event_name == 'release'
57+ build-native :
58+ name : Build Native Binary
6259 strategy :
6360 matrix :
6461 include :
65- - os : linux
66- arch : amd64
67- - os : linux
68- arch : arm64
69- - os : darwin
70- arch : amd64
71- - os : darwin
72- arch : arm64
73-
62+ - os : ubuntu-latest
63+ goos : linux
64+ goarch : amd64
65+ - os : ubuntu-latest
66+ goos : linux
67+ goarch : arm64
68+ - os : macos-latest
69+ goos : darwin
70+ goarch : amd64
71+ - os : macos-latest
72+ goos : darwin
73+ goarch : arm64
74+ runs-on : ${{ matrix.os }}
75+ needs : test
76+ if : github.event_name == 'push' || github.event_name == 'release'
7477 steps :
7578 - name : Checkout code
7679 uses : actions/checkout@v4
7780
78- - name : Set up Docker Buildx
79- uses : docker/setup-buildx-action@v3
81+ - name : Set up Go
82+ uses : actions/setup-go@v4
83+ with :
84+ go-version : ' 1.21'
85+
86+ - name : Set up Node.js
87+ uses : actions/setup-node@v4
88+ with :
89+ node-version : ' 18'
8090
81- - name : Build for ${{ matrix.os }}/${{ matrix.arch }}
91+ - name : Install Node.js dependencies
92+ run : cd web && npm ci
93+
94+ - name : Build dashboard
95+ run : |
96+ cd web
97+ npm run build
98+ mkdir -p ../internal/dashboard/web
99+ cp -r dist ../internal/dashboard/web/
100+
101+ - name : Build Lambda function
102+ run : |
103+ mkdir -p cmd/lambda-nat-proxy/assets
104+ cd lambda
105+ GOOS=linux GOARCH=amd64 go build -o ../cmd/lambda-nat-proxy/assets/bootstrap .
106+ chmod +x ../cmd/lambda-nat-proxy/assets/bootstrap
107+
108+ - name : Build binary for ${{ matrix.goos }}/${{ matrix.goarch }}
109+ env :
110+ GOOS : ${{ matrix.goos }}
111+ GOARCH : ${{ matrix.goarch }}
82112 run : |
83- # Create build directory
84113 mkdir -p build
114+ CGO_ENABLED=0 go build -a -installsuffix cgo -o build/lambda-nat-proxy ./cmd/lambda-nat-proxy
85115
86- # Create platform-specific Dockerfile
87- cat > Dockerfile.release << 'EOF'
88- FROM node:18-alpine AS dashboard-builder
89- WORKDIR /app
90- COPY web/package*.json ./web/
91- WORKDIR /app/web
92- RUN npm ci --only=production
93- COPY web/ .
94- RUN npm run build
95-
96- FROM golang:1.21-alpine AS go-builder
97- ARG TARGETOS
98- ARG TARGETARCH
99- RUN apk add --no-cache git
100- WORKDIR /app
101- COPY . .
102- COPY --from=dashboard-builder /app/web/dist ./internal/dashboard/web/dist
103- RUN sed -i 's|replace github.com/dan-v/lambda-nat-punch-proxy => ..|replace github.com/dan-v/lambda-nat-punch-proxy => /app|' lambda/go.mod
104- RUN go mod download && cd lambda && go mod download
105- RUN cd lambda && GOOS=linux GOARCH=amd64 go build -o ../cmd/lambda-nat-proxy/assets/bootstrap .
106- RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -a -installsuffix cgo -o lambda-nat-proxy ./cmd/lambda-nat-proxy
107-
108- FROM scratch
109- COPY --from=go-builder /app/lambda-nat-proxy .
110- COPY --from=go-builder /app/cmd/lambda-nat-proxy/assets/bootstrap ./bootstrap
111- EOF
112-
113- # Build for specific platform
114- docker buildx build \
115- --platform ${{ matrix.os }}/${{ matrix.arch }} \
116- --build-arg TARGETOS=${{ matrix.os }} \
117- --build-arg TARGETARCH=${{ matrix.arch }} \
118- --file Dockerfile.release \
119- --output type=local,dest=./build-output \
120- .
121-
122- # Set binary name
123- BINARY_NAME="lambda-nat-proxy"
124- PLATFORM_DIR="build/${{ matrix.os }}-${{ matrix.arch }}"
125-
126- # Create platform directory and copy binaries
127- mkdir -p "$PLATFORM_DIR"
128- cp build-output/lambda-nat-proxy "$PLATFORM_DIR/$BINARY_NAME"
129- cp build-output/bootstrap "$PLATFORM_DIR/bootstrap"
130-
131- # Make executable
132- chmod +x "$PLATFORM_DIR/$BINARY_NAME"
133- chmod +x "$PLATFORM_DIR/bootstrap"
134-
135- # Create archive
116+ # Copy bootstrap to build directory
117+ cp cmd/lambda-nat-proxy/assets/bootstrap build/
118+
119+ - name : Create archive
120+ run : |
136121 cd build
137- tar -czf "lambda-nat-proxy-${{ matrix.os }}-${{ matrix.arch }}.tar.gz" "${{ matrix.os }}-${{ matrix.arch }}/"
138-
139- # Cleanup
140- rm -rf ../build-output ../Dockerfile.release
122+ tar -czf lambda-nat-proxy-${{ matrix.goos }}-${{ matrix.goarch }}.tar.gz lambda-nat-proxy bootstrap
123+ mv lambda-nat-proxy-${{ matrix.goos }}-${{ matrix.goarch }}.tar.gz ../
141124
142- - name : Upload build artifacts
125+ - name : Upload build artifact
143126 uses : actions/upload-artifact@v4
144127 with :
145- name : lambda-nat-proxy-${{ matrix.os }}-${{ matrix.arch }}
146- path : build/ lambda-nat-proxy-${{ matrix.os }}-${{ matrix.arch }}.tar.gz
128+ name : lambda-nat-proxy-${{ matrix.goos }}-${{ matrix.goarch }}
129+ path : lambda-nat-proxy-${{ matrix.goos }}-${{ matrix.goarch }}.tar.gz
147130 retention-days : 30
148131
149132 release :
150133 name : Create Release
151134 runs-on : ubuntu-latest
152- needs : build-matrix
135+ needs : build-native
153136 if : github.event_name == 'release'
154137 permissions :
155138 contents : write
0 commit comments