Skip to content

Add dashboard screenshot to README #5

Add dashboard screenshot to README

Add dashboard screenshot to README #5

name: Build and Release
on:
push:
branches: [ main, master ]
pull_request:
branches: [ main, master ]
release:
types: [ published ]
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
test:
name: Run Tests
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.21'
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
- name: Cache Go modules
uses: actions/cache@v3
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Cache Node modules
uses: actions/cache@v3
with:
path: web/node_modules
key: ${{ runner.os }}-node-${{ hashFiles('web/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install Node.js dependencies
run: cd web && npm ci
- name: Run tests
run: make test
build-matrix:
name: Build Binaries
runs-on: ubuntu-latest
needs: test
if: github.event_name == 'push' || github.event_name == 'release'
strategy:
matrix:
include:
- os: linux
arch: amd64
- os: linux
arch: arm64
- os: darwin
arch: amd64
- os: darwin
arch: arm64
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build for ${{ matrix.os }}/${{ matrix.arch }}
run: |
# Create build directory
mkdir -p build
# Create platform-specific Dockerfile
cat > Dockerfile.release << 'EOF'
FROM node:18-alpine AS dashboard-builder
WORKDIR /app
COPY web/package*.json ./web/
WORKDIR /app/web
RUN npm ci --only=production
COPY web/ .
RUN npm run build
FROM golang:1.21-alpine AS go-builder
ARG TARGETOS
ARG TARGETARCH
RUN apk add --no-cache git
WORKDIR /app
COPY . .
COPY --from=dashboard-builder /app/web/dist ./internal/dashboard/web/dist
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
RUN go mod download && cd lambda && go mod download
RUN cd lambda && GOOS=linux GOARCH=amd64 go build -o ../cmd/lambda-nat-proxy/assets/bootstrap .
RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -a -installsuffix cgo -o lambda-nat-proxy ./cmd/lambda-nat-proxy
FROM scratch
COPY --from=go-builder /app/lambda-nat-proxy .
COPY --from=go-builder /app/cmd/lambda-nat-proxy/assets/bootstrap ./bootstrap
EOF
# Build for specific platform
docker buildx build \
--platform ${{ matrix.os }}/${{ matrix.arch }} \
--build-arg TARGETOS=${{ matrix.os }} \
--build-arg TARGETARCH=${{ matrix.arch }} \
--file Dockerfile.release \
--output type=local,dest=./build-output \
.
# Set binary name
BINARY_NAME="lambda-nat-proxy"
PLATFORM_DIR="build/${{ matrix.os }}-${{ matrix.arch }}"
# Create platform directory and copy binaries
mkdir -p "$PLATFORM_DIR"
cp build-output/lambda-nat-proxy "$PLATFORM_DIR/$BINARY_NAME"
cp build-output/bootstrap "$PLATFORM_DIR/bootstrap"
# Make executable
chmod +x "$PLATFORM_DIR/$BINARY_NAME"
chmod +x "$PLATFORM_DIR/bootstrap"
# Create archive
cd build
tar -czf "lambda-nat-proxy-${{ matrix.os }}-${{ matrix.arch }}.tar.gz" "${{ matrix.os }}-${{ matrix.arch }}/"
# Cleanup
rm -rf ../build-output ../Dockerfile.release
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: lambda-nat-proxy-${{ matrix.os }}-${{ matrix.arch }}
path: build/lambda-nat-proxy-${{ matrix.os }}-${{ matrix.arch }}.tar.gz
retention-days: 30
release:
name: Create Release
runs-on: ubuntu-latest
needs: build-matrix
if: github.event_name == 'release'
permissions:
contents: write
steps:
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
- name: Display structure of downloaded files
run: ls -la artifacts/
- name: Upload release assets
uses: softprops/action-gh-release@v1
with:
files: artifacts/**/*.tar.gz
fail_on_unmatched_files: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
docker:
name: Build and Push Docker Image
runs-on: ubuntu-latest
needs: test
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master')
permissions:
contents: read
packages: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=sha,prefix={{branch}}-
type=raw,value=latest,enable={{is_default_branch}}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile.build
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max