Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker Push Github Action #83

Merged
merged 11 commits into from
Jun 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 35 additions & 13 deletions .github/workflows/build_and_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,53 @@ on:
- "**/*.png"
env:
GO_VERSION: 1.18.2
ENVOY_GATEWAY_DEV_IMAGE: envoyproxy/gateway-dev
ENVOY_GATEWAY_DEV_TAG: latest
jobs:
build:
build-and-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: ${{ env.GO_VERSION }}
cache: true
- name: build
run: make build
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: ${{ env.GO_VERSION }}
cache: true
- name: test and report coverage
- name: Build
run: make build-all
- name: Test and report coverage
run: go test ./... -race -coverprofile=coverage.xml -covermode=atomic
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v2
with:
fail_ci_if_error: true
files: ./coverage.xml
name: codecov-envoy-gateway
verbose: true
verbose: true
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Build
uses: docker/build-push-action@v3
with:
file: ./Dockerfile
context: bin
platforms: linux/amd64
tags: ${{ env.ENVOY_GATEWAY_DEV_IMAGE }}:${{ github.sha }}
skriss marked this conversation as resolved.
Show resolved Hide resolved
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Login to DockerHub
if: github.event_name == 'push'
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Push to envoyproxy/gateway-dev
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
uses: docker/build-push-action@v3
with:
file: ./Dockerfile
context: bin
platforms: linux/amd64,linux/arm64
skriss marked this conversation as resolved.
Show resolved Hide resolved
push: true
tags: ${{ env.ENVOY_GATEWAY_DEV_IMAGE }}:${{ github.sha }}, ${{ env.ENVOY_GATEWAY_DEV_IMAGE }}:${{ env.ENVOY_GATEWAY_DEV_TAG }}
cache-from: type=gha
cache-to: type=gha,mode=max
9 changes: 9 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Use distroless as minimal base image to package the manager binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
FROM gcr.io/distroless/static:nonroot
ARG TARGETPLATFORM
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest defaulting this arg to linux/amd64 so it just works for a regular docker build invocation:

Suggested change
ARG TARGETPLATFORM
ARG TARGETPLATFORM=linux/amd64

Copy link
Contributor Author

@arkodg arkodg Jun 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it will never work for a docker build . invocation now :)

=> ERROR [2/2] COPY linux/amd64/envoy-gateway /usr/local/bin/ 

since the Dockerfile is only a means for packaging the binary and the binary is built on the host , relates to http://github.com/envoyproxy/gateway/issues/93

Instead we need to rely on make docker-build now

As for TARGETPLATFORM=linux/amd64, we dont need this, by default it picks the right value

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I run make docker-build as is, then docker run the image, I get exec /usr/local/bin/envoy-gateway: no such file or directory. If I add the default I suggested, then do the same, I get Manages Envoy Proxy as a standalone or Kubernetes-based application gateway as expected.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is environment dependent, if you did docker buildx install then your docker build is buildx otherwise it's not. Though defaults to linux/amd64 doesn't do right thing for M1 mac users whose docker is linux/arm64.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, set environment DOCKER_BUILDKIT=1 in the Makefile should make thing work? @skriss

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, understood, was just trying to have this work OOTB for the most environments. Since you're against the default, let's document the buildx requirement in https://github.com/envoyproxy/gateway/blob/main/CONTRIBUTING.md.

COPY $TARGETPLATFORM/envoy-gateway /usr/local/bin/

USER 65532:65532

ENTRYPOINT ["/usr/local/bin/envoy-gateway"]
34 changes: 32 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,38 @@
# Golang variables
GOOS ?= $(shell go env GOOS)
GOARCH ?= $(shell go env GOARCH)

# Docker variables
# REGISTRY is the image registry to use for build and push image targets.
REGISTRY ?= docker.io/envoyproxy
# IMAGE is the image URL for build and push image targets.
IMAGE ?= ${REGISTRY}/gateway-dev
# REV is the short git sha of latest commit.
REV=$(shell git rev-parse --short HEAD)
# Tag is the tag to use for build and push image targets.
TAG ?= $(REV)

.PHONY: build
build:
@go build -o ./bin/ github.com/envoyproxy/gateway/cmd/envoy-gateway
build: ## Build the envoy-gateway binary
@CGO_ENABLED=0 go build -a -o ./bin/${GOOS}/${GOARCH}/ github.com/envoyproxy/gateway/cmd/envoy-gateway

build-linux-amd64:
@GOOS=linux GOARCH=amd64 $(MAKE) build

build-linux-arm64:
@GOOS=linux GOARCH=arm64 $(MAKE) build

build-all: build-linux-amd64 build-linux-arm64

.PHONY: test
test:
@go test ./...

.PHONY: docker-build
docker-build: build-all ## Build the envoy-gateway docker image.
@DOCKER_BUILDKIT=1 docker build -t $(IMAGE):$(TAG) -f Dockerfile bin

.PHONY: docker-push
docker-push: ## Push the docker image for envoy-gateway.
docker push $(IMAGE):$(TAG)