From 19c275cfd5c3b8fe70aa92686c7b6e41ca5ae388 Mon Sep 17 00:00:00 2001 From: Joao Morais Date: Sun, 13 Jun 2021 21:21:31 -0300 Subject: [PATCH] build: move from travis to github actions - remove push image from travis - add builder/multi stage Dockerfile - add make's docker-builder step - add workflow: build image - update workflow: add build+tests for push events on `master` and `release-*` --- .github/workflows/build.yaml | 21 ++++++++++++++++ .github/workflows/image.yaml | 45 ++++++++++++++++++++++++++++++++++ .travis.yml | 2 +- Makefile | 4 +++ builder/Dockerfile | 47 ++++++++++++++++++++++++++++++++++++ 5 files changed, 118 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/build.yaml create mode 100644 .github/workflows/image.yaml create mode 100644 builder/Dockerfile diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml new file mode 100644 index 000000000..2826a8a2b --- /dev/null +++ b/.github/workflows/build.yaml @@ -0,0 +1,21 @@ +name: build +on: + push: + branches: + - master + - 'release-*' + pull_request: + branches: + - master +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/setup-go@v1 + with: + go-version: 1.13.15 + - uses: actions/checkout@v2 + - name: Run build + run: go build -o haproxy-ingress pkg/main.go + - name: Run tests + run: go test ./... diff --git a/.github/workflows/image.yaml b/.github/workflows/image.yaml new file mode 100644 index 000000000..805bee366 --- /dev/null +++ b/.github/workflows/image.yaml @@ -0,0 +1,45 @@ +name: image +on: + push: + tags: + - '*' +jobs: + build-image: + runs-on: ubuntu-latest + env: + EXTRA_TAGS: + steps: + - name: Configure envvars + run: | + GIT_TAG="${GITHUB_REF#refs/tags/}" + TAGS=$( + for repository in quay.io/jcmoraisjr jcmoraisjr; do + for project in haproxy-ingress; do + for tag in "$GIT_TAG" ${{ env.EXTRA_TAGS }}; do + echo -n "${repository}/${project}:${tag}," + done + done + done + ) + echo "GIT_TAG=$GIT_TAG" >> $GITHUB_ENV + echo "TAGS=$TAGS" >> $GITHUB_ENV + - uses: actions/checkout@v2 + - uses: docker/login-action@v1 + with: + username: jcmoraisjr + password: ${{ secrets.DOCKERHUB_TOKEN }} + - uses: docker/login-action@v1 + with: + registry: quay.io + username: ${{ secrets.QUAY_USERNAME }} + password: ${{ secrets.QUAY_TOKEN }} + - uses: docker/setup-buildx-action@v1 + - uses: docker/build-push-action@v2 + with: + context: . + file: builder/Dockerfile + platforms: linux/amd64 + push: true + build-args: | + GIT_TAG=${{ env.GIT_TAG }} + tags: ${{ env.TAGS }} diff --git a/.travis.yml b/.travis.yml index 2e2bdb656..fba83820d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,7 @@ services: - docker sudo: required script: -- make build test tag-push +- make build test branches: only: - master diff --git a/Makefile b/Makefile index 09551623a..645dc95d7 100644 --- a/Makefile +++ b/Makefile @@ -29,3 +29,7 @@ install: CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(GOARCH) go install \ -v -installsuffix cgo \ $(ROOT_PKG) + +.PHONY: docker-builder +docker-builder: + docker build -t $(REPO):$(TAG) . -f builder/Dockerfile diff --git a/builder/Dockerfile b/builder/Dockerfile new file mode 100644 index 000000000..25b9a5926 --- /dev/null +++ b/builder/Dockerfile @@ -0,0 +1,47 @@ +# Copyright 2021 The HAProxy Ingress Controller Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +FROM golang:1.13.15-alpine AS builder + +ARG GIT_TAG + +RUN apk --no-cache add git + +COPY / /src + +RUN cd /src\ + && GIT_TAG=${GIT_TAG:-latest}\ + && GIT_COMMIT=git-$(git rev-parse --short HEAD)\ + && GIT_REPO=$(git config --get remote.origin.url)\ + && VERSION_PKG=github.com/jcmoraisjr/haproxy-ingress/pkg/version\ + && CGO_ENABLED=0 go build\ + -ldflags "-s -w -X ${VERSION_PKG}.RELEASE=${GIT_TAG} -X ${VERSION_PKG}.COMMIT=${GIT_COMMIT} -X ${VERSION_PKG}.REPO=${GIT_REPO}"\ + -o haproxy-ingress pkg/main.go + +FROM haproxy:2.1.12-alpine + +RUN apk --no-cache add socat openssl lua5.3 lua-socket dumb-init + +COPY rootfs/ / +COPY --from=builder /src/haproxy-ingress /haproxy-ingress-controller + +RUN deluser haproxy\ + && addgroup -g 1001 haproxy\ + && adduser -u 1001 -G haproxy -D -s /bin/false haproxy\ + && mkdir -p /var/empty /etc/haproxy /var/lib/haproxy /var/run/haproxy\ + && chown -R haproxy:haproxy /etc/haproxy /var/lib/haproxy /var/run/haproxy\ + && chmod 0 /var/empty + +STOPSIGNAL SIGTERM +ENTRYPOINT ["/usr/bin/dumb-init", "--", "/start.sh"]