Skip to content

Commit

Permalink
CI/CD: Remove build_dev workflow and optimize Dockerfile
Browse files Browse the repository at this point in the history
- Comment out entire build_dev.yml workflow
- Refactor Dockerfile for multi-arch support and local builds
- Optimize image size and streamline container setup
  • Loading branch information
bnema committed Aug 27, 2024
1 parent 9002bf8 commit 746cfe6
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 47 deletions.
78 changes: 39 additions & 39 deletions .github/workflows/build_dev.yml
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
name: Build and Test Gordon

on:
push:
branches:
- "dev"

jobs:
build-and-test:
name: Build and Test
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
env:
KO_DOCKER_REPO: ghcr.io/${{ github.repository }}

steps:
- uses: actions/setup-go@v4
with:
go-version: "1.23"

- uses: actions/checkout@v3

# - name: Run tests
# run: go test ./...

- name: Log in to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- uses: ko-build/setup-ko@v0.6

- name: Build and push with ko
run: |
ko build --platform=linux/amd64,linux/arm64 --bare --tags=dev -B ./cmd/cli --base-import-paths=false --image-refs=gordon-dev
# name: Build and Test Gordon

# on:
# push:
# branches:
# - "dev"

# jobs:
# build-and-test:
# name: Build and Test
# runs-on: ubuntu-latest
# permissions:
# contents: read
# packages: write
# env:
# KO_DOCKER_REPO: ghcr.io/${{ github.repository }}

# steps:
# - uses: actions/setup-go@v4
# with:
# go-version: "1.23"

# - uses: actions/checkout@v3

# # - name: Run tests
# # run: go test ./...

# - name: Log in to GitHub Container Registry
# uses: docker/login-action@v2
# with:
# registry: ghcr.io
# username: ${{ github.actor }}
# password: ${{ secrets.GITHUB_TOKEN }}

# - uses: ko-build/setup-ko@v0.6

# - name: Build and push with ko
# run: |
# ko build --platform=linux/amd64,linux/arm64 --bare --tags=dev -B ./cmd/cli --base-import-paths=false --image-refs=gordon-dev
19 changes: 11 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
# Use a minimal base image
FROM alpine
# Install ca-certificates bundle
RUN apk update && apk add ca-certificates && rm -rf /var/cache/apk/*
# Copy the binary
COPY gordon /gordon
# Copy other necessary files
COPY .iscontainer /
# Start from scratch
FROM alpine:latest

ARG ARCH

# Copy the pre-built binary for the specific architecture
COPY dist/gordon-linux-${ARCH} /gordon
# Create the .iscontainer file
RUN touch /.iscontainer

# Set the entrypoint
ENTRYPOINT ["/gordon"]

# Default command
CMD ["serve"]
38 changes: 38 additions & 0 deletions buildpush-dev.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash

set -e

REPO="ghcr.io/bnema/gordon"
TAG="dev"
DIST_DIR="./dist"

# Ensure dist directory exists
mkdir -p $DIST_DIR

# Build Go binaries for multiple platforms with CGO_ENABLED=0
echo "Building Go binaries..."
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o $DIST_DIR/gordon-linux-amd64 ./cmd/cli
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -o $DIST_DIR/gordon-linux-arm64 ./cmd/cli

# Build Docker images for each architecture
echo "Building Docker images..."
docker build -t $REPO:${TAG}-amd64 --build-arg ARCH=amd64 -f Dockerfile .
docker build -t $REPO:${TAG}-arm64v8 --build-arg ARCH=arm64 -f Dockerfile .

# Push images
echo "Pushing Docker images..."
docker push $REPO:${TAG}-amd64
docker push $REPO:${TAG}-arm64v8

# Create and push multi-arch manifest
echo "Creating and pushing multi-arch manifest..."
docker manifest create $REPO:$TAG \
$REPO:${TAG}-amd64 \
$REPO:${TAG}-arm64v8 \
--amend

# Annotate the arm64 image with variant information
docker manifest annotate $REPO:$TAG \
$REPO:${TAG}-arm64v8 --arch arm64 --variant v8

docker manifest push $REPO:$TAG

0 comments on commit 746cfe6

Please sign in to comment.