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

Move to a single Dockerfile #43

Merged
merged 2 commits into from
Feb 9, 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
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build_output
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/build_output
.DS_Store
nginx-asg-sync
55 changes: 30 additions & 25 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,48 +1,53 @@
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
GOLANG_CONTAINER = golang:1.15
BUILD_IN_CONTAINER = 1
GOFLAGS ?= -mod=vendor

all: amazon centos7 ubuntu-xenial amazon2 ubuntu-bionic
export DOCKER_BUILDKIT = 1

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

.PHONY: test
test:
ifeq ($(BUILD_IN_CONTAINER),1)
$(GO_DOCKER_RUN) $(GOLANG_CONTAINER) go test
else
GO111MODULE=on GOFLAGS='$(GOFLAGS)' go test ./...
endif

lint:
golangci-lint run

compile: test
ifeq ($(BUILD_IN_CONTAINER),1)
$(GO_DOCKER_RUN) $(GOLANG_CONTAINER) go build -o /build_output/nginx-asg-sync
else
GO111MODULE=on GOFLAGS='$(GOFLAGS)' go build -o ./build_output/nginx-asg-sync github.com/nginxinc/nginx-asg-sync/cmd/sync
endif

amazon: compile
make -C build/package/builders/amazon/
amazon:
docker build -t amazon-builder --target rpm_based --build-arg CONTAINER_VERSION=amazonlinux:1 -f build/Dockerfile .
docker run --rm -v $(shell pwd)/build/package/rpm:/rpm -v $(shell pwd)/build_output:/build_output amazon-builder

amazon2: compile
make -C build/package/builders/amazon2/
amazon2:
docker build -t amazon2-builder --target rpm_based --build-arg CONTAINER_VERSION=amazonlinux:2 -f build/Dockerfile .
docker run --rm -v $(shell pwd)/build/package/rpm:/rpm -v $(shell pwd)/build_output:/build_output amazon2-builder

centos7: compile
make -C build/package/builders/centos7/
centos7:
docker build -t centos7-builder --target rpm_based --build-arg CONTAINER_VERSION=centos:7 -f build/Dockerfile .
docker run --rm -v $(shell pwd)/build/package/rpm:/rpm -v $(shell pwd)/build_output:/build_output centos7-builder

ubuntu-xenial: compile
make -C build/package/builders/ubuntu-xenial/
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 .
docker run --rm -v $(shell pwd)/build/package/debian:/debian -v $(shell pwd)/build_output:/build_output ubuntu-xenial-builder

ubuntu-bionic: compile
make -C build/package/builders/ubuntu-bionic/
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 .
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 .
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 .
docker run --rm -v $(shell pwd)/build/package/debian:/debian -v $(shell pwd)/build_output:/build_output ubuntu-groovy-builder

.PHONY: clean
clean:
-rm -r build_output

.PHONY: test
.PHONY: deps
deps:
@go mod tidy && go mod verify && go mod vendor

.PHONY: clean-cache
clean-cache:
@go clean -modcache
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
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 and 18.04, CentOS7/RHEL7 and Amazon Linux 2, run: `$ sudo service nginx-asg-sync start|stop|restart`
For Ubuntu 16.04, 18.04, 20.04, CentOS7/RHEL7 and Amazon Linux 2, run: `$ sudo service nginx-asg-sync start|stop|restart`

## Troubleshooting

Expand All @@ -169,6 +169,8 @@ where `<os>` is the target OS. The following values are allowed:
* `centos7` for CentOS7/RHEL7
* `ubuntu-xenial` for Ubuntu 16.04
* `ubuntu-bionic` for Ubuntu 18.04
* `ubuntu-focal` for Ubuntu 20.04
* `ubuntu-groovy` for Ubuntu 20.10

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

Expand Down
35 changes: 35 additions & 0 deletions build/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
ARG CONTAINER_VERSION=ubuntu:groovy
ARG GOLANG_CONTAINER=golang:1.15

FROM $GOLANG_CONTAINER 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

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

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"]

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

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
ENV PACKAGE_VERSION=${PACKAGE_VERSION}
ENV OS_VERSION=${OS_VERSION}

ENTRYPOINT ["/build.sh"]
6 changes: 0 additions & 6 deletions build/package/builders/amazon/Dockerfile

This file was deleted.

2 changes: 0 additions & 2 deletions build/package/builders/amazon/Makefile

This file was deleted.

6 changes: 0 additions & 6 deletions build/package/builders/amazon2/Dockerfile

This file was deleted.

2 changes: 0 additions & 2 deletions build/package/builders/amazon2/Makefile

This file was deleted.

6 changes: 0 additions & 6 deletions build/package/builders/amazon2/build.sh

This file was deleted.

6 changes: 0 additions & 6 deletions build/package/builders/centos7/Dockerfile

This file was deleted.

2 changes: 0 additions & 2 deletions build/package/builders/centos7/Makefile

This file was deleted.

6 changes: 0 additions & 6 deletions build/package/builders/centos7/build.sh

This file was deleted.

13 changes: 13 additions & 0 deletions build/package/builders/deb_based/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

# 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/
sed -i "s/%%CODENAME%%/${OS_VERSION}/g" debian/changelog
rm debian/nginx-asg-sync.upstart
dpkg-buildpackage -us -uc
cd ..
mv *.deb /build_output/
6 changes: 0 additions & 6 deletions build/package/builders/ubuntu-bionic/Dockerfile

This file was deleted.

2 changes: 0 additions & 2 deletions build/package/builders/ubuntu-bionic/Makefile

This file was deleted.

11 changes: 0 additions & 11 deletions build/package/builders/ubuntu-bionic/build.sh

This file was deleted.

6 changes: 0 additions & 6 deletions build/package/builders/ubuntu-xenial/Dockerfile

This file was deleted.

2 changes: 0 additions & 2 deletions build/package/builders/ubuntu-xenial/Makefile

This file was deleted.

11 changes: 0 additions & 11 deletions build/package/builders/ubuntu-xenial/build.sh

This file was deleted.

2 changes: 1 addition & 1 deletion build/package/debian/rules
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@

override_dh_auto_install:
dh_auto_install
/usr/bin/install -m 755 /build_output/nginx-asg-sync debian/nginx-asg-sync/usr/sbin/
/usr/bin/install -m 755 /nginx-asg-sync debian/nginx-asg-sync/usr/sbin/
/usr/bin/install -m 644 debian/config.yaml.example debian/nginx-asg-sync/etc/nginx/
2 changes: 1 addition & 1 deletion build/package/rpm/SPECS/nginx-asg-sync.spec
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ with AWS Auto Scaling groups and Azure Virtual Machine Scale Sets
rm -rf %{buildroot}
mkdir -p %{buildroot}%{_sbindir}/

install -m 755 -p /build_output/nginx-asg-sync %{buildroot}%{_sbindir}/
install -m 755 -p /nginx-asg-sync %{buildroot}%{_sbindir}/

%if %{use_systemd}
mkdir -p %{buildroot}%{_unitdir}
Expand Down