CI/CD: Remove build_dev workflow and optimize Dockerfile
- Comment out entire build_dev.yml workflow - Refactor Dockerfile for multi-arch support and local builds - Optimize image size and streamline container setup
- commit
- 0461a54ec596094b11c67be61193bd024b2276aa
- author
- bamen · · 2024-08-26 19:51 UTC
- committer
- bamen · · 2024-08-26 17:43 UTC
- parent
- 932fd9f
- signature
- unsigned
3 files · +88 -47
M .github/workflows/build_dev.yml +39 -39
| @@ -1,39 +1,39 @@ | |||
| 1 | - | name: Build and Test Gordon | |
| 2 | - | ||
| 3 | - | on: | |
| 4 | - | push: | |
| 5 | - | branches: | |
| 6 | - | - "dev" | |
| 7 | - | ||
| 8 | - | jobs: | |
| 9 | - | build-and-test: | |
| 10 | - | name: Build and Test | |
| 11 | - | runs-on: ubuntu-latest | |
| 12 | - | permissions: | |
| 13 | - | contents: read | |
| 14 | - | packages: write | |
| 15 | - | env: | |
| 16 | - | KO_DOCKER_REPO: ghcr.io/${{ github.repository }} | |
| 17 | - | ||
| 18 | - | steps: | |
| 19 | - | - uses: actions/setup-go@v4 | |
| 20 | - | with: | |
| 21 | - | go-version: "1.23" | |
| 22 | - | ||
| 23 | - | - uses: actions/checkout@v3 | |
| 24 | - | ||
| 25 | - | # - name: Run tests | |
| 26 | - | # run: go test ./... | |
| 27 | - | ||
| 28 | - | - name: Log in to GitHub Container Registry | |
| 29 | - | uses: docker/login-action@v2 | |
| 30 | - | with: | |
| 31 | - | registry: ghcr.io | |
| 32 | - | username: ${{ github.actor }} | |
| 33 | - | password: ${{ secrets.GITHUB_TOKEN }} | |
| 34 | - | ||
| 35 | - | - uses: ko-build/setup-ko@v0.6 | |
| 36 | - | ||
| 37 | - | - name: Build and push with ko | |
| 38 | - | run: | | |
| 39 | - | ko build --platform=linux/amd64,linux/arm64 --bare --tags=dev -B ./cmd/cli --base-import-paths=false --image-refs=gordon-dev | |
| 1 | + | # name: Build and Test Gordon | |
| 2 | + | ||
| 3 | + | # on: | |
| 4 | + | # push: | |
| 5 | + | # branches: | |
| 6 | + | # - "dev" | |
| 7 | + | ||
| 8 | + | # jobs: | |
| 9 | + | # build-and-test: | |
| 10 | + | # name: Build and Test | |
| 11 | + | # runs-on: ubuntu-latest | |
| 12 | + | # permissions: | |
| 13 | + | # contents: read | |
| 14 | + | # packages: write | |
| 15 | + | # env: | |
| 16 | + | # KO_DOCKER_REPO: ghcr.io/${{ github.repository }} | |
| 17 | + | ||
| 18 | + | # steps: | |
| 19 | + | # - uses: actions/setup-go@v4 | |
| 20 | + | # with: | |
| 21 | + | # go-version: "1.23" | |
| 22 | + | ||
| 23 | + | # - uses: actions/checkout@v3 | |
| 24 | + | ||
| 25 | + | # # - name: Run tests | |
| 26 | + | # # run: go test ./... | |
| 27 | + | ||
| 28 | + | # - name: Log in to GitHub Container Registry | |
| 29 | + | # uses: docker/login-action@v2 | |
| 30 | + | # with: | |
| 31 | + | # registry: ghcr.io | |
| 32 | + | # username: ${{ github.actor }} | |
| 33 | + | # password: ${{ secrets.GITHUB_TOKEN }} | |
| 34 | + | ||
| 35 | + | # - uses: ko-build/setup-ko@v0.6 | |
| 36 | + | ||
| 37 | + | # - name: Build and push with ko | |
| 38 | + | # run: | | |
| 39 | + | # ko build --platform=linux/amd64,linux/arm64 --bare --tags=dev -B ./cmd/cli --base-import-paths=false --image-refs=gordon-dev | |
| @@ -1,39 +1,39 @@ | |||||
| 1 | - | name: Build and Test Gordon | 1 | + | # name: Build and Test Gordon |
| 2 | - | 2 | + | ||
| 3 | - | on: | 3 | + | # on: |
| 4 | - | push: | 4 | + | # push: |
| 5 | - | branches: | 5 | + | # branches: |
| 6 | - | - "dev" | 6 | + | # - "dev" |
| 7 | - | 7 | + | ||
| 8 | - | jobs: | 8 | + | # jobs: |
| 9 | - | build-and-test: | 9 | + | # build-and-test: |
| 10 | - | name: Build and Test | 10 | + | # name: Build and Test |
| 11 | - | runs-on: ubuntu-latest | 11 | + | # runs-on: ubuntu-latest |
| 12 | - | permissions: | 12 | + | # permissions: |
| 13 | - | contents: read | 13 | + | # contents: read |
| 14 | - | packages: write | 14 | + | # packages: write |
| 15 | - | env: | 15 | + | # env: |
| 16 | - | KO_DOCKER_REPO: ghcr.io/${{ github.repository }} | 16 | + | # KO_DOCKER_REPO: ghcr.io/${{ github.repository }} |
| 17 | - | 17 | + | ||
| 18 | - | steps: | 18 | + | # steps: |
| 19 | - | - uses: actions/setup-go@v4 | 19 | + | # - uses: actions/setup-go@v4 |
| 20 | - | with: | 20 | + | # with: |
| 21 | - | go-version: "1.23" | 21 | + | # go-version: "1.23" |
| 22 | - | 22 | + | ||
| 23 | - | - uses: actions/checkout@v3 | 23 | + | # - uses: actions/checkout@v3 |
| 24 | - | 24 | + | ||
| 25 | - | # - name: Run tests | 25 | + | # # - name: Run tests |
| 26 | - | # run: go test ./... | 26 | + | # # run: go test ./... |
| 27 | - | 27 | + | ||
| 28 | - | - name: Log in to GitHub Container Registry | 28 | + | # - name: Log in to GitHub Container Registry |
| 29 | - | uses: docker/login-action@v2 | 29 | + | # uses: docker/login-action@v2 |
| 30 | - | with: | 30 | + | # with: |
| 31 | - | registry: ghcr.io | 31 | + | # registry: ghcr.io |
| 32 | - | username: ${{ github.actor }} | 32 | + | # username: ${{ github.actor }} |
| 33 | - | password: ${{ secrets.GITHUB_TOKEN }} | 33 | + | # password: ${{ secrets.GITHUB_TOKEN }} |
| 34 | - | 34 | + | ||
| 35 | - | - uses: ko-build/setup-ko@v0.6 | 35 | + | # - uses: ko-build/setup-ko@v0.6 |
| 36 | - | 36 | + | ||
| 37 | - | - name: Build and push with ko | 37 | + | # - name: Build and push with ko |
| 38 | - | run: | | 38 | + | # run: | |
| 39 | - | ko build --platform=linux/amd64,linux/arm64 --bare --tags=dev -B ./cmd/cli --base-import-paths=false --image-refs=gordon-dev | 39 | + | # ko build --platform=linux/amd64,linux/arm64 --bare --tags=dev -B ./cmd/cli --base-import-paths=false --image-refs=gordon-dev |
M Dockerfile +11 -8
| @@ -1,12 +1,15 @@ | |||
| 1 | - | # Use a minimal base image | |
| 2 | - | FROM alpine | |
| 3 | - | # Install ca-certificates bundle | |
| 4 | - | RUN apk update && apk add ca-certificates && rm -rf /var/cache/apk/* | |
| 5 | - | # Copy the binary | |
| 6 | - | COPY gordon /gordon | |
| 7 | - | # Copy other necessary files | |
| 8 | - | COPY .iscontainer / | |
| 1 | + | # Start from scratch | |
| 2 | + | FROM alpine:latest | |
| 3 | + | ||
| 4 | + | ARG ARCH | |
| 5 | + | ||
| 6 | + | # Copy the pre-built binary for the specific architecture | |
| 7 | + | COPY dist/gordon-linux-${ARCH} /gordon | |
| 8 | + | # Create the .iscontainer file | |
| 9 | + | RUN touch /.iscontainer | |
| 10 | + | ||
| 9 | 11 | # Set the entrypoint | |
| 10 | 12 | ENTRYPOINT ["/gordon"] | |
| 13 | + | ||
| 11 | 14 | # Default command | |
| 12 | 15 | CMD ["serve"] | |
| @@ -1,12 +1,15 @@ | |||||
| 1 | - | # Use a minimal base image | 1 | + | # Start from scratch |
| 2 | - | FROM alpine | 2 | + | FROM alpine:latest |
| 3 | - | # Install ca-certificates bundle | 3 | + | |
| 4 | - | RUN apk update && apk add ca-certificates && rm -rf /var/cache/apk/* | 4 | + | ARG ARCH |
| 5 | - | # Copy the binary | 5 | + | |
| 6 | - | COPY gordon /gordon | 6 | + | # Copy the pre-built binary for the specific architecture |
| 7 | - | # Copy other necessary files | 7 | + | COPY dist/gordon-linux-${ARCH} /gordon |
| 8 | - | COPY .iscontainer / | 8 | + | # Create the .iscontainer file |
| 9 | + | RUN touch /.iscontainer | |||
| 10 | + | ||||
| 9 | # Set the entrypoint | 11 | # Set the entrypoint | ||
| 10 | ENTRYPOINT ["/gordon"] | 12 | ENTRYPOINT ["/gordon"] | ||
| 13 | + | ||||
| 11 | # Default command | 14 | # Default command | ||
| 12 | CMD ["serve"] | 15 | CMD ["serve"] | ||
A buildpush-dev.sh +38 -0
| @@ -0,0 +1,38 @@ | |||
| 1 | + | #!/bin/bash | |
| 2 | + | ||
| 3 | + | set -e | |
| 4 | + | ||
| 5 | + | REPO="ghcr.io/bnema/gordon" | |
| 6 | + | TAG="dev" | |
| 7 | + | DIST_DIR="./dist" | |
| 8 | + | ||
| 9 | + | # Ensure dist directory exists | |
| 10 | + | mkdir -p $DIST_DIR | |
| 11 | + | ||
| 12 | + | # Build Go binaries for multiple platforms with CGO_ENABLED=0 | |
| 13 | + | echo "Building Go binaries..." | |
| 14 | + | CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o $DIST_DIR/gordon-linux-amd64 ./cmd/cli | |
| 15 | + | CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -o $DIST_DIR/gordon-linux-arm64 ./cmd/cli | |
| 16 | + | ||
| 17 | + | # Build Docker images for each architecture | |
| 18 | + | echo "Building Docker images..." | |
| 19 | + | docker build -t $REPO:${TAG}-amd64 --build-arg ARCH=amd64 -f Dockerfile . | |
| 20 | + | docker build -t $REPO:${TAG}-arm64v8 --build-arg ARCH=arm64 -f Dockerfile . | |
| 21 | + | ||
| 22 | + | # Push images | |
| 23 | + | echo "Pushing Docker images..." | |
| 24 | + | docker push $REPO:${TAG}-amd64 | |
| 25 | + | docker push $REPO:${TAG}-arm64v8 | |
| 26 | + | ||
| 27 | + | # Create and push multi-arch manifest | |
| 28 | + | echo "Creating and pushing multi-arch manifest..." | |
| 29 | + | docker manifest create $REPO:$TAG \ | |
| 30 | + | $REPO:${TAG}-amd64 \ | |
| 31 | + | $REPO:${TAG}-arm64v8 \ | |
| 32 | + | --amend | |
| 33 | + | ||
| 34 | + | # Annotate the arm64 image with variant information | |
| 35 | + | docker manifest annotate $REPO:$TAG \ | |
| 36 | + | $REPO:${TAG}-arm64v8 --arch arm64 --variant v8 | |
| 37 | + | ||
| 38 | + | docker manifest push $REPO:$TAG | |
| @@ -0,0 +1,38 @@ | |||||
| 1 | + | #!/bin/bash | |||
| 2 | + | ||||
| 3 | + | set -e | |||
| 4 | + | ||||
| 5 | + | REPO="ghcr.io/bnema/gordon" | |||
| 6 | + | TAG="dev" | |||
| 7 | + | DIST_DIR="./dist" | |||
| 8 | + | ||||
| 9 | + | # Ensure dist directory exists | |||
| 10 | + | mkdir -p $DIST_DIR | |||
| 11 | + | ||||
| 12 | + | # Build Go binaries for multiple platforms with CGO_ENABLED=0 | |||
| 13 | + | echo "Building Go binaries..." | |||
| 14 | + | CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o $DIST_DIR/gordon-linux-amd64 ./cmd/cli | |||
| 15 | + | CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -o $DIST_DIR/gordon-linux-arm64 ./cmd/cli | |||
| 16 | + | ||||
| 17 | + | # Build Docker images for each architecture | |||
| 18 | + | echo "Building Docker images..." | |||
| 19 | + | docker build -t $REPO:${TAG}-amd64 --build-arg ARCH=amd64 -f Dockerfile . | |||
| 20 | + | docker build -t $REPO:${TAG}-arm64v8 --build-arg ARCH=arm64 -f Dockerfile . | |||
| 21 | + | ||||
| 22 | + | # Push images | |||
| 23 | + | echo "Pushing Docker images..." | |||
| 24 | + | docker push $REPO:${TAG}-amd64 | |||
| 25 | + | docker push $REPO:${TAG}-arm64v8 | |||
| 26 | + | ||||
| 27 | + | # Create and push multi-arch manifest | |||
| 28 | + | echo "Creating and pushing multi-arch manifest..." | |||
| 29 | + | docker manifest create $REPO:$TAG \ | |||
| 30 | + | $REPO:${TAG}-amd64 \ | |||
| 31 | + | $REPO:${TAG}-arm64v8 \ | |||
| 32 | + | --amend | |||
| 33 | + | ||||
| 34 | + | # Annotate the arm64 image with variant information | |||
| 35 | + | docker manifest annotate $REPO:$TAG \ | |||
| 36 | + | $REPO:${TAG}-arm64v8 --arch arm64 --variant v8 | |||
| 37 | + | ||||
| 38 | + | docker manifest push $REPO:$TAG | |||