Skip to content

Commit

Permalink
build: move from travis to github actions
Browse files Browse the repository at this point in the history
- 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-*`
  • Loading branch information
jcmoraisjr committed Jun 14, 2021
1 parent 365dc28 commit 19c275c
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 1 deletion.
21 changes: 21 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -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 ./...
45 changes: 45 additions & 0 deletions .github/workflows/image.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ services:
- docker
sudo: required
script:
- make build test tag-push
- make build test
branches:
only:
- master
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
47 changes: 47 additions & 0 deletions builder/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]

0 comments on commit 19c275c

Please sign in to comment.