Skip to content

Commit

Permalink
Merge pull request #4 from adevinta/maiao.I30584aba676613cde91987aedc…
Browse files Browse the repository at this point in the history
…021a1773916d5e

Build the image in GHA
  • Loading branch information
zonzamas authored Oct 3, 2024
2 parents 568fcf4 + 5440c06 commit 067ad92
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 2 deletions.
55 changes: 55 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: build images

on:
workflow_call:
push:
branches: [ "*", "**/*" ]

jobs:

buildImages:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v3
with:
go-version: '^1.23'

- name: Set up Docker context for Buildx
id: buildx-context
run: |
docker context create builders
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2
with:
version: latest
endpoint: builders

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

- name: Build images
id: buildimages
run: |
img=ghcr.io/${{github.repository}}:${{github.sha}}
echo "::set-output name=IMAGE_NAME::${img}"
docker pull ${img} || (
docker buildx build --push --cache-to type=gha,mode=max --cache-from type=gha --progress plain --platform linux/arm64/v8,linux/amd64 --build-arg BUILDKIT_INLINE_CACHE=1 -t ${img} .
)
- name: Build main image images
id: buildmainimage
if: ${{ github.ref == 'refs/heads/main' && github.event_name != 'pull_request' }}
run: |
img=ghcr.io/${{github.repository}}:latest
echo "::set-output name=IMAGE_NAME::${img}"
docker buildx build --push --cache-to type=gha,mode=max --cache-from type=gha --progress plain --platform linux/arm64/v8,linux/amd64 --build-arg BUILDKIT_INLINE_CACHE=1 -t ${img} .
3 changes: 1 addition & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@ WORKDIR /workspace
# Copy the Go Modules manifests
COPY go.mod go.mod
COPY go.sum go.sum
COPY vendor/ vendor/

# Copy the go source
COPY cmd cmd
#COPY api/ api/
COPY pkg/ pkg/

# Build
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -mod=vendor -a -o manager ./cmd/traffic-controller
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -o manager ./cmd/traffic-controller

# Use distroless as minimal base image to package the manager binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
Expand Down

0 comments on commit 067ad92

Please sign in to comment.