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

Add local target in Dockerfile and build for centos8 #66

Merged
merged 3 commits into from
Feb 22, 2021
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
75 changes: 43 additions & 32 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,31 +31,20 @@ jobs:
steps:
- name: Checkout Repository
uses: actions/checkout@v2
- name: Fetch Cached Artifacts
- name: Setup Golang Environment
uses: actions/setup-go@v2
with:
go-version: '${{ env.GOLANG_VERSION }}'
- name: Build Binary
run: >
make build
env:
GOFLAGS: '-mod=vendor -gcflags=-trimpath=${{ github.workspace }} -asmflags=-trimpath=${{ github.workspace }}'
- name: Store Artifacts in Cache
uses: actions/cache@v2.1.4
with:
path: ${{ github.workspace }}/nginx-asg-sync
key: nginx-asg-sync-${{ github.run_id }}-${{ github.run_number }}
- name: Docker Buildx
uses: docker/setup-buildx-action@v1
with:
driver-opts: network=host
- name: Cache Docker layers
uses: actions/cache@v2.1.4
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Build Image
uses: docker/build-push-action@v2
with:
file: build/Dockerfile
context: '.'
target: builder
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
tags: nginx/nginx-asg-sync:${{ github.sha }}

unit-tests:
name: Unit Tests
Expand Down Expand Up @@ -98,13 +87,14 @@ jobs:
with:
file: build/Dockerfile
context: '.'
target: rpm_based
target: local
load: true
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
tags: amazon-builder:${{ github.sha }}
build-args: |
CONTAINER_VERSION=amazonlinux:1
OS_TYPE=rpm_based
- name: Run Amazon 1
uses: addnab/docker-run-action@v2
with:
Expand All @@ -116,13 +106,14 @@ jobs:
with:
file: build/Dockerfile
context: '.'
target: rpm_based
target: local
load: true
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
tags: amazon2-builder:${{ github.sha }}
build-args: |
CONTAINER_VERSION=amazonlinux:2
OS_TYPE=rpm_based
- name: Run Amazon 2
uses: addnab/docker-run-action@v2
with:
Expand All @@ -134,32 +125,52 @@ jobs:
with:
file: build/Dockerfile
context: '.'
target: rpm_based
target: local
load: true
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
tags: centos7-builder:${{ github.sha }}
build-args: |
CONTAINER_VERSION=centos:7
OS_TYPE=rpm_based
- name: Run Centos 7
uses: addnab/docker-run-action@v2
with:
image: centos7-builder:${{ github.sha }}
run: /build.sh
options: -v ${{ github.workspace }}/build/package/rpm:/rpm -v ${{ github.workspace }}/build_output:/build_output
- name: Build Image Centos 8
uses: docker/build-push-action@v2
with:
file: build/Dockerfile
context: '.'
target: local
load: true
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
tags: centos8-builder:${{ github.sha }}
build-args: |
CONTAINER_VERSION=centos:8
OS_TYPE=rpm_based
- name: Run Centos 8
uses: addnab/docker-run-action@v2
with:
image: centos8-builder:${{ github.sha }}
run: /build.sh
options: -v ${{ github.workspace }}/build/package/rpm:/rpm -v ${{ github.workspace }}/build_output:/build_output
- name: Build Image Ubuntu Xenial
uses: docker/build-push-action@v2
with:
file: build/Dockerfile
context: '.'
target: deb_based
target: local
load: true
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
tags: ubuntu-xenial-builder:${{ github.sha }}
build-args: |
CONTAINER_VERSION=ubuntu:xenial
OS_VERSION=xenial
OS_TYPE=deb_based
- name: Run Ubuntu Xenial
uses: addnab/docker-run-action@v2
with:
Expand All @@ -171,14 +182,14 @@ jobs:
with:
file: build/Dockerfile
context: '.'
target: deb_based
target: local
load: true
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
tags: ubuntu-bionic-builder:${{ github.sha }}
build-args: |
CONTAINER_VERSION=ubuntu:bionic
OS_VERSION=bionic
OS_TYPE=deb_based
- name: Run Ubuntu Bionic
uses: addnab/docker-run-action@v2
with:
Expand All @@ -190,14 +201,14 @@ jobs:
with:
file: build/Dockerfile
context: '.'
target: deb_based
target: local
load: true
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
tags: ubuntu-focal-builder:${{ github.sha }}
build-args: |
CONTAINER_VERSION=ubuntu:focal
OS_VERSION=focal
OS_TYPE=deb_based
- name: Run Ubuntu Focal
uses: addnab/docker-run-action@v2
with:
Expand All @@ -209,14 +220,14 @@ jobs:
with:
file: build/Dockerfile
context: '.'
target: deb_based
target: local
load: true
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
tags: ubuntu-groovy-builder:${{ github.sha }}
build-args: |
CONTAINER_VERSION=ubuntu:groovy
OS_VERSION=groovy
OS_TYPE=deb_based
- name: Run Ubuntu Groovy
uses: addnab/docker-run-action@v2
with:
Expand Down
41 changes: 26 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
GO_DOCKER_RUN = docker run --rm -v $(shell pwd):/go/src/github.com/nginxinc/nginx-asg-sync -v $(shell pwd)/build_output:/build_output -w /go/src/github.com/nginxinc/nginx-asg-sync/cmd/sync
GOFLAGS ?= -mod=vendor
TARGET ?= local

export DOCKER_BUILDKIT = 1

all: amazon centos7 ubuntu-xenial amazon2 ubuntu-bionic ubuntu-focal ubuntu-groovy
all: amazon centos7 centos8 ubuntu-xenial amazon2 ubuntu-bionic ubuntu-focal ubuntu-groovy

.PHONY: test
test:
Expand All @@ -12,32 +13,42 @@ test:
lint:
golangci-lint run

amazon:
docker build -t amazon-builder --target rpm_based --build-arg CONTAINER_VERSION=amazonlinux:1 -f build/Dockerfile .
.PHONY: build
build:
ifeq (${TARGET},local)
CGO_ENABLED=0 GO111MODULE=on GOFLAGS='$(GOFLAGS)' GOOS=linux go build -installsuffix cgo -o nginx-asg-sync github.com/nginxinc/nginx-asg-sync/cmd/sync
endif

amazon: build
docker build -t amazon-builder --target ${TARGET} --build-arg CONTAINER_VERSION=amazonlinux:1 --build-arg OS_TYPE=rpm_based -f build/Dockerfile .
docker run --rm -v $(shell pwd)/build/package/rpm:/rpm -v $(shell pwd)/build_output:/build_output amazon-builder

amazon2:
docker build -t amazon2-builder --target rpm_based --build-arg CONTAINER_VERSION=amazonlinux:2 -f build/Dockerfile .
amazon2: build
docker build -t amazon2-builder --target ${TARGET} --build-arg CONTAINER_VERSION=amazonlinux:2 --build-arg OS_TYPE=rpm_based -f build/Dockerfile .
docker run --rm -v $(shell pwd)/build/package/rpm:/rpm -v $(shell pwd)/build_output:/build_output amazon2-builder

centos7:
docker build -t centos7-builder --target rpm_based --build-arg CONTAINER_VERSION=centos:7 -f build/Dockerfile .
centos7: build
docker build -t centos7-builder --target ${TARGET} --build-arg CONTAINER_VERSION=centos:7 --build-arg OS_TYPE=rpm_based -f build/Dockerfile .
docker run --rm -v $(shell pwd)/build/package/rpm:/rpm -v $(shell pwd)/build_output:/build_output centos7-builder

ubuntu-xenial:
docker build -t ubuntu-xenial-builder --target deb_based --build-arg CONTAINER_VERSION=ubuntu:xenial --build-arg OS_VERSION=xenial -f build/Dockerfile .
centos8: build
docker build -t centos8-builder --target ${TARGET} --build-arg CONTAINER_VERSION=centos:8 --build-arg OS_TYPE=rpm_based -f build/Dockerfile .
docker run --rm -v $(shell pwd)/build/package/rpm:/rpm -v $(shell pwd)/build_output:/build_output centos8-builder

ubuntu-xenial: build
docker build -t ubuntu-xenial-builder --target ${TARGET} --build-arg CONTAINER_VERSION=ubuntu:xenial --build-arg OS_TYPE=deb_based -f build/Dockerfile .
docker run --rm -v $(shell pwd)/build/package/debian:/debian -v $(shell pwd)/build_output:/build_output ubuntu-xenial-builder

ubuntu-bionic:
docker build -t ubuntu-bionic-builder --target deb_based --build-arg CONTAINER_VERSION=ubuntu:bionic --build-arg OS_VERSION=bionic -f build/Dockerfile .
ubuntu-bionic: build
docker build -t ubuntu-bionic-builder --target ${TARGET} --build-arg CONTAINER_VERSION=ubuntu:bionic --build-arg OS_TYPE=deb_based -f build/Dockerfile .
docker run --rm -v $(shell pwd)/build/package/debian:/debian -v $(shell pwd)/build_output:/build_output ubuntu-bionic-builder

ubuntu-focal:
docker build -t ubuntu-focal-builder --target deb_based --build-arg CONTAINER_VERSION=ubuntu:focal --build-arg OS_VERSION=focal -f build/Dockerfile .
ubuntu-focal: build
docker build -t ubuntu-focal-builder --target ${TARGET} --build-arg CONTAINER_VERSION=ubuntu:focal --build-arg OS_TYPE=deb_based -f build/Dockerfile .
docker run --rm -v $(shell pwd)/build/package/debian:/debian -v $(shell pwd)/build_output:/build_output ubuntu-focal-builder

ubuntu-groovy:
docker build -t ubuntu-groovy-builder --target deb_based --build-arg CONTAINER_VERSION=ubuntu:groovy --build-arg OS_VERSION=groovy -f build/Dockerfile .
ubuntu-groovy: build
docker build -t ubuntu-groovy-builder --target ${TARGET} --build-arg CONTAINER_VERSION=ubuntu:groovy --build-arg OS_TYPE=deb_based -f build/Dockerfile .
docker run --rm -v $(shell pwd)/build/package/debian:/debian -v $(shell pwd)/build_output:/build_output ubuntu-groovy-builder

.PHONY: clean
Expand Down
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ Below you will find documentation on how to use nginx-asg-sync.

We provide packages for the following operating systems:

* Ubuntu: 16.04 (Xenial), 18.04 (Bionic)
* CentOS/RHEL: 7
* Ubuntu: 16.04 (Xenial), 18.04 (Bionic), 20.04 (Focal), 20.10 (Groovy)
* CentOS/RHEL: 7, 8
* Amazon Linux: 1, 2

Support for other operating systems can be added.
Expand Down Expand Up @@ -150,7 +150,7 @@ nginx-asg-sync runs as a system service and supports the start/stop/restart comm

For Amazon Linux 1, run: `$ sudo start|stop|restart nginx-asg-sync`

For Ubuntu 16.04, 18.04, 20.04, CentOS7/RHEL7 and Amazon Linux 2, run: `$ sudo service nginx-asg-sync start|stop|restart`
For Ubuntu 16.04, 18.04, 20.04, 20.10, CentOS7/RHEL7, CentOS8/RHEL8 and Amazon Linux 2, run: `$ sudo service nginx-asg-sync start|stop|restart`

## Troubleshooting

Expand All @@ -161,17 +161,23 @@ If nginx-asg-sync doesn’t work as expected, check its log file available at **
You can compile nginx-asg-sync and build a software package using the provided Makefile. Before you start building a package, make sure that the following software is installed on your system:
* make
* Docker
* Go (optional, to build the binary locally)

To build a software package, run: `$ make <os>`
where `<os>` is the target OS. The following values are allowed:
* `amazon` for Amazon Linux 1
* `amazon2` for Amazon Linux 2
* `centos7` for CentOS7/RHEL7
* `centos8` for CentOS8/RHEL8
* `ubuntu-xenial` for Ubuntu 16.04
* `ubuntu-bionic` for Ubuntu 18.04
* `ubuntu-focal` for Ubuntu 20.04
* `ubuntu-groovy` for Ubuntu 20.10

by default the nginx-asg-sync binary will be built locally, to build it inside a Docker container add the `TARGET` parameter to `make`, for example:

`$ make ubuntu-focal TARGET=container`

If you run make without any arguments, it will build software packages for all supported OSes.

## Support
Expand Down
28 changes: 19 additions & 9 deletions build/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
ARG CONTAINER_VERSION=ubuntu:groovy
ARG GOLANG_CONTAINER=golang:1.15
ARG OS_TYPE=deb_based
ARG PACKAGE_VERSION=0.4-1

FROM $GOLANG_CONTAINER AS builder
FROM golang:1.15-alpine AS builder
WORKDIR /go/src/github.com/nginxinc/nginx-asg-sync/cmd/sync
COPY . /go/src/github.com/nginxinc/nginx-asg-sync/

RUN go build -o /nginx-asg-sync
RUN CGO_ENABLED=0 GOFLAGS='-mod=vendor' go build -installsuffix cgo -o /nginx-asg-sync

#---------------------------------------------------------------------------------------------

Expand All @@ -14,8 +15,6 @@ FROM ${CONTAINER_VERSION} as rpm_based
RUN yum install -y rpmdevtools
ADD build/package/builders/rpm_based/build.sh /

COPY --from=builder /nginx-asg-sync /nginx-asg-sync

ENTRYPOINT ["/build.sh"]

#---------------------------------------------------------------------------------------------
Expand All @@ -25,11 +24,22 @@ FROM ${CONTAINER_VERSION} as deb_based
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install debhelper dh-systemd -y
ADD build/package/builders/deb_based/build.sh /

COPY --from=builder /nginx-asg-sync /nginx-asg-sync

ARG PACKAGE_VERSION
ARG OS_VERSION
ARG CONTAINER_VERSION
ENV PACKAGE_VERSION=${PACKAGE_VERSION}
ENV OS_VERSION=${OS_VERSION}
ENV CONTAINER_VERSION=${CONTAINER_VERSION}

ENTRYPOINT ["/build.sh"]

#---------------------------------------------------------------------------------------------

FROM ${OS_TYPE} as container

COPY --from=builder /nginx-asg-sync /nginx-asg-sync


#---------------------------------------------------------------------------------------------

FROM ${OS_TYPE} as local

COPY nginx-asg-sync /nginx-asg-sync
10 changes: 6 additions & 4 deletions build/package/builders/deb_based/build.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#!/bin/bash

# package_name=nginx-asg-sync-${PACKAGE_VERSION}
package_name=nginx-asg-sync-${PACKAGE_VERSION}

export SYSTEMD='--with=systemd'
mkdir -p ~/nginx-asg-sync/
cp -r /debian ~/nginx-asg-sync/
cd ~/nginx-asg-sync/
export OS_VERSION=${CONTAINER_VERSION#*:}

mkdir -p ~/${package_name}/
cp -r /debian ~/${package_name}/
cd ~/${package_name}/
sed -i "s/%%CODENAME%%/${OS_VERSION}/g" debian/changelog
rm debian/nginx-asg-sync.upstart
dpkg-buildpackage -us -uc
Expand Down
10 changes: 5 additions & 5 deletions cmd/sync/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ import (
nginx "github.com/nginxinc/nginx-plus-go-client/client"
)

var configFile = flag.String("config_path", "/etc/nginx/config.yaml", "Path to the config file")
var logFile = flag.String("log_path", "", "Path to the log file. If the file doesn't exist, it will be created")
var version = "0.4-1"
var (
configFile = flag.String("config_path", "/etc/nginx/config.yaml", "Path to the config file")
logFile = flag.String("log_path", "", "Path to the log file. If the file doesn't exist, it will be created")
version = "0.4-1"
)

const connTimeoutInSecs = 10

Expand Down Expand Up @@ -63,7 +65,6 @@ func main() {

httpClient := &http.Client{Timeout: connTimeoutInSecs * time.Second}
nginxClient, err := nginx.NewNginxClient(httpClient, commonConfig.APIEndpoint)

if err != nil {
log.Printf("Couldn't create NGINX client: %v", err)
os.Exit(10)
Expand Down Expand Up @@ -102,7 +103,6 @@ func main() {
for {
for _, upstream := range upstreams {
ips, err := cloudProviderClient.GetPrivateIPsForScalingGroup(upstream.ScalingGroup)

if err != nil {
log.Printf("Couldn't get the IP addresses for %v: %v", upstream.ScalingGroup, err)
continue
Expand Down