Skip to content

Commit

Permalink
Create separate builds for CentOS7 (+fips)
Browse files Browse the repository at this point in the history
Add new buildboxes for centos7 and centos7-fips.

For now, we will continue to support both CentOS 6 and 7.
Eventually we will drop support for CentOS 6, and the only
supported CentOS builds will be these new CentOS 7 builds.

Fixes #9028
  • Loading branch information
zmb3 committed Dec 1, 2021
1 parent 38b24f6 commit ffa69bc
Show file tree
Hide file tree
Showing 10 changed files with 553 additions and 111 deletions.
273 changes: 243 additions & 30 deletions .drone.yml

Large diffs are not rendered by default.

32 changes: 17 additions & 15 deletions build.assets/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -69,24 +69,15 @@ RUN (groupadd ci --gid=$GID -o && useradd ci --uid=$UID --gid=$GID --create-home
mkdir -p -m0700 /var/lib/teleport && chown -R ci /var/lib/teleport)

# Install Rust
#
# Rust installation based on official rust image Dockerfile here:
# https://github.com/rust-lang/docker-rust/blob/master/1.56.0/bullseye/Dockerfile
#
# The original Rust docker image uses a script to install `rustup`, and from
# there rustc and associated tools.
#
# Rather than execute an arbitrary `rustup` installation script, we are cherry-
# picking the appropriate files off the official docker image and then installing
# the extra tooling/targets we need.

ENV RUSTUP_HOME=/usr/local/rustup \
ARG RUST_VERSION
ENV RUSTUP_HOME=/usr/local/rustup \
CARGO_HOME=/usr/local/cargo \
PATH=/usr/local/cargo/bin:$PATH \
RUST_VERSION=1.56.1
RUST_VERSION=$RUST_VERSION

RUN mkdir -p $RUSTUP_HOME && chmod a+w $RUSTUP_HOME && \
mkdir -p $CARGO_HOME/registry && chmod -R a+w $CARGO_HOME

COPY --from=rust:1.56.1 /usr/local/rustup /usr/local/rustup
COPY --from=rust:1.56.1 /usr/local/cargo /usr/local/cargo
RUN set -eux \
rustup --version; \
cargo --version; \
Expand All @@ -98,6 +89,17 @@ RUN set -eux \
rustup target list | grep installed; \
rustc --version;

RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile minimal --default-toolchain $RUST_VERSION && \
rustup --version && \
cargo --version && \
rustc --version && \
rustup component add --toolchain $RUST_VERSION-x86_64-unknown-linux-gnu rustfmt clippy && \
chmod -R a+w $RUSTUP_HOME $CARGO_HOME && \
rustup target add i686-unknown-linux-gnu && \
rustup target add arm-unknown-linux-gnueabihf && \
rustup target add aarch64-unknown-linux-gnu && \
cargo install cbindgen

# Install etcd.
RUN (curl -L https://github.com/coreos/etcd/releases/download/v3.3.9/etcd-v3.3.9-linux-amd64.tar.gz | tar -xz && \
cp etcd-v3.3.9-linux-amd64/etcd* /bin/)
Expand Down
60 changes: 60 additions & 0 deletions build.assets/Dockerfile-centos7
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
FROM centos:7

ENV LANGUAGE=en_US.UTF-8 \
LANG=en_US.UTF-8 \
LC_ALL=en_US.UTF-8 \
LC_CTYPE=en_US.UTF-8

ARG RUNTIME
ARG RUST_VERSION

ARG UID
ARG GID
RUN (groupadd ci --gid=$GID -o && useradd ci --uid=$UID --gid=$GID --create-home --shell=/bin/sh && \
mkdir -p -m0700 /var/lib/teleport && chown -R ci /var/lib/teleport)

# Install dev tools (make, etc) and a Perl package needed to build OpenSSL.
RUN yum groupinstall -y "Development Tools"
RUN yum install -y pam-devel net-tools tree git zip perl-IPC-Cmd && \
yum clean all

# Install etcd.
RUN (curl -L https://github.com/coreos/etcd/releases/download/v3.3.9/etcd-v3.3.9-linux-amd64.tar.gz | tar -xz && \
cp etcd-v3.3.9-linux-amd64/etcd* /bin/)

# Install Go.
RUN mkdir -p /opt && cd /opt && curl https://storage.googleapis.com/golang/$RUNTIME.linux-amd64.tar.gz | tar xz && \
mkdir -p /go/src/github.com/gravitational/teleport && \
chmod a+w /go && \
chmod a+w /var/lib && \
/opt/go/bin/go version

# Install PAM module and policies for testing.
COPY pam/ /opt/pam_teleport/
RUN make -C /opt/pam_teleport install

# Install Rust.
ENV RUSTUP_HOME=/usr/local/rustup \
CARGO_HOME=/usr/local/cargo \
PATH=/usr/local/cargo/bin:$PATH \
RUST_VERSION=$RUST_VERSION

RUN mkdir -p $RUSTUP_HOME && chmod a+w $RUSTUP_HOME && \
mkdir -p $CARGO_HOME/registry && chmod -R a+w $CARGO_HOME

RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile minimal --default-toolchain $RUST_VERSION && \
rustup --version && \
cargo --version && \
rustc --version && \
rustup component add --toolchain $RUST_VERSION-x86_64-unknown-linux-gnu rustfmt clippy && \
chmod -R a+w $RUSTUP_HOME $CARGO_HOME && \
cargo install cbindgen

ENV GOPATH="/go" \
GOROOT="/opt/go" \
PATH="/opt/bin:$PATH:/opt/go/bin:/go/bin:/go/src/github.com/gravitational/teleport/build"

RUN chmod a-w /

VOLUME ["/go/src/github.com/gravitational/teleport"]
EXPOSE 6600 2379 2380
69 changes: 69 additions & 0 deletions build.assets/Dockerfile-centos7-fips
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
FROM centos:7

ENV LANGUAGE=en_US.UTF-8 \
LANG=en_US.UTF-8 \
LC_ALL=en_US.UTF-8 \
LC_CTYPE=en_US.UTF-8

ARG RUST_VERSION
ARG BORINGCRYPTO_RUNTIME
ARG GO_BOOTSTRAP_RUNTIME=go1.9.7

ARG UID
ARG GID
RUN (groupadd ci --gid=$GID -o && useradd ci --uid=$UID --gid=$GID --create-home --shell=/bin/sh && \
mkdir -p -m0700 /var/lib/teleport && chown -R ci /var/lib/teleport)

# Install dev tools (make, etc) and a Perl package needed to build OpenSSL.
RUN yum groupinstall -y "Development Tools"
RUN yum install -y pam-devel net-tools tree git zip perl-IPC-Cmd && \
yum clean all

# Install etcd.
RUN (curl -L https://github.com/coreos/etcd/releases/download/v3.3.9/etcd-v3.3.9-linux-amd64.tar.gz | tar -xz && \
cp etcd-v3.3.9-linux-amd64/etcd* /bin/)

# BoringCrypto (unlike regular Go) requires glibc 2.14, so we have to build from source.
# 1) Install older binary Go runtime for bootstrapping
# 2) Get source for the correct Go boringcrypto runtime and compile it with Go bootstrap runtime
# 3) Erase Go bootstrap runtime and create build directories
# 4) Print compiled Go version
RUN mkdir -p /go-bootstrap && cd /go-bootstrap && curl https://dl.google.com/go/${GO_BOOTSTRAP_RUNTIME}.linux-amd64.tar.gz | tar xz && \
mkdir -p /opt && cd /opt && curl https://go-boringcrypto.storage.googleapis.com/${BORINGCRYPTO_RUNTIME}.src.tar.gz | tar xz && \
cd /opt/go/src && GOROOT_BOOTSTRAP=/go-bootstrap/go ./make.bash && \
rm -rf /go-bootstrap && \
mkdir -p /go/src/github.com/gravitational/teleport && \
chmod a+w /go && \
chmod a+w /var/lib && \
chmod a-w / && \
/opt/go/bin/go version

# Install PAM module and policies for testing.
COPY pam/ /opt/pam_teleport/
RUN make -C /opt/pam_teleport install

# Install Rust.
ENV RUSTUP_HOME=/usr/local/rustup \
CARGO_HOME=/usr/local/cargo \
PATH=/usr/local/cargo/bin:$PATH \
RUST_VERSION=$RUST_VERSION

RUN mkdir -p $RUSTUP_HOME && chmod a+w $RUSTUP_HOME && \
mkdir -p $CARGO_HOME/registry && chmod -R a+w $CARGO_HOME

RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile minimal --default-toolchain $RUST_VERSION && \
rustup --version && \
cargo --version && \
rustc --version && \
rustup component add --toolchain $RUST_VERSION-x86_64-unknown-linux-gnu rustfmt clippy && \
chmod -R a+w $RUSTUP_HOME $CARGO_HOME && \
cargo install cbindgen

ENV GOPATH="/go" \
GOROOT="/opt/go" \
PATH="/opt/bin:$PATH:/opt/go/bin:/go/bin:/go/src/github.com/gravitational/teleport/build"

RUN chmod a-w /

VOLUME ["/go/src/github.com/gravitational/teleport"]
EXPOSE 6600 2379 2380
85 changes: 79 additions & 6 deletions build.assets/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ TEST_KUBE ?=
OS ?= linux
ARCH ?= amd64
RUNTIME ?= go1.17.2
RUST_VERSION ?= 1.56.1
BORINGCRYPTO_RUNTIME=$(RUNTIME)b7
LIBBPF_VERSION ?= 0.3.1

Expand All @@ -30,6 +31,8 @@ GOGO_PROTO_TAG ?= v1.3.2
BUILDBOX=quay.io/gravitational/teleport-buildbox:$(RUNTIME)
BUILDBOX_FIPS=quay.io/gravitational/teleport-buildbox-fips:$(RUNTIME)
BUILDBOX_CENTOS6=quay.io/gravitational/teleport-buildbox-centos6:$(RUNTIME)
BUILDBOX_CENTOS7=quay.io/gravitational/teleport-buildbox-centos7:$(RUNTIME)
BUILDBOX_CENTOS7_FIPS=quay.io/gravitational/teleport-buildbox-centos7-fips:$(RUNTIME)
BUILDBOX_ARM=quay.io/gravitational/teleport-buildbox-arm:$(RUNTIME)
BUILDBOX_ARM_FIPS=quay.io/gravitational/teleport-buildbox-arm-fips:$(RUNTIME)

Expand Down Expand Up @@ -107,6 +110,7 @@ buildbox:
--build-arg UID=$(UID) \
--build-arg GID=$(GID) \
--build-arg RUNTIME=$(RUNTIME) \
--build-arg RUST_VERSION=$(RUST_VERSION) \
--build-arg PROTOC_VER=$(PROTOC_VER) \
--build-arg GOGO_PROTO_TAG=$(GOGO_PROTO_TAG) \
--build-arg PROTOC_PLATFORM=$(PROTOC_PLATFORM) \
Expand Down Expand Up @@ -147,6 +151,34 @@ buildbox-centos6:
# CentOS 6 FIPS builds were removed in Teleport 7.0
# https://github.com/gravitational/teleport/issues/7207

#
# Builds a Docker buildbox for CentOS 7 builds
#
.PHONY:buildbox-centos7
buildbox-centos7:
@if [[ $${DRONE} == "true" ]] && ! docker inspect --type=image $(BUILDBOX_CENTOS7) 2>&1 >/dev/null; then docker pull $(BUILDBOX_CENTOS7) || true; fi;
docker build \
--build-arg UID=$(UID) \
--build-arg GID=$(GID) \
--build-arg RUNTIME=$(RUNTIME) \
--build-arg RUST_VERSION=$(RUST_VERSION) \
--cache-from $(BUILDBOX_CENTOS7) \
--tag $(BUILDBOX_CENTOS7) -f Dockerfile-centos7 .

#
# Builds a Docker buildbox for CentOS 7 FIPS builds
#
.PHONY:buildbox-centos7-fips
buildbox-centos7-fips:
@if [[ $${DRONE} == "true" ]] && ! docker inspect --type=image $(BUILDBOX_CENTOS7_FIPS) 2>&1 >/dev/null; then docker pull $(BUILDBOX_CENTOS7_FIPS) || true; fi;
docker build \
--build-arg UID=$(UID) \
--build-arg GID=$(GID) \
--build-arg BORINGCRYPTO_RUNTIME=$(BORINGCRYPTO_RUNTIME) \
--build-arg RUST_VERSION=$(RUST_VERSION) \
--cache-from $(BUILDBOX_CENTOS7_FIPS) \
--tag $(BUILDBOX_CENTOS7_FIPS) -f Dockerfile-centos7-fips .

#
# Builds a Docker buildbox for ARMv7/ARM64 builds
# ARM buildboxes use a regular Teleport buildbox as a base which already has a user
Expand Down Expand Up @@ -287,6 +319,14 @@ release-arm64: buildbox-arm
release-amd64-centos6: buildbox-centos6
$(MAKE) release-centos6 ARCH=amd64

.PHONY: release-amd64-centos7
release-amd64-centos7: buildbox-centos7
$(MAKE) release-centos7 ARCH=amd64

.PHONY: release-amd64-centos7-fips
release-amd64-centos7-fips: buildbox-centos7-fips
$(MAKE) release-centos7-fips ARCH=amd64 FIPS=yes

#
# Create a Teleport FIPS package using the build container.
# This is a special case because it only builds and packages the Enterprise FIPS binaries, no OSS.
Expand All @@ -300,12 +340,30 @@ release-fips: buildbox-fips

#
# Create a Teleport package for CentOS 6 using the build container.
# DELETE IN 9.0 (zmb3)
#
.PHONY:release-centos6
release-centos6: buildbox-centos6
docker run $(DOCKERFLAGS) -i $(NOROOT) $(BUILDBOX_CENTOS6) \
/usr/bin/make release -e ADDFLAGS="$(ADDFLAGS)" OS=$(OS) ARCH=$(ARCH) RUNTIME=$(RUNTIME) REPRODUCIBLE=no

#
# Create a Teleport package for CentOS 7 using the build container.
#
.PHONY:release-centos7
release-centos7: buildbox-centos7
docker run $(DOCKERFLAGS) -i $(NOROOT) $(BUILDBOX_CENTOS7) \
/usr/bin/make release -e ADDFLAGS="$(ADDFLAGS)" OS=$(OS) ARCH=$(ARCH) RUNTIME=$(RUNTIME) REPRODUCIBLE=no

#
# Create a Teleport FIPS package for CentOS 7 using the build container.
# This only builds and packages enterprise FIPS binaries, no OSS.
#
.PHONY:release-centos7-fips
release-centos7-fips:
docker run $(DOCKERFLAGS) -i $(NOROOT) $(BUILDBOX_CENTOS7_FIPS) \
/usr/bin/make -C e release -e ADDFLAGS="$(ADDFLAGS)" OS=$(OS) ARCH=$(ARCH) RUNTIME=$(RUNTIME) FIPS=yes VERSION=$(VERSION) GITTAG=v$(VERSION) REPRODUCIBLE=no

#
# Create a Windows Teleport package using the build container.
#
Expand All @@ -325,18 +383,33 @@ release-windows-unsigned: buildbox
#
# Run docs tester to detect problems.
#
.PHONY: docsbox
.PHONY:docsbox
docsbox:
if ! docker inspect --type=image $(DOCSBOX) 2>&1 >/dev/null; then docker pull $(DOCSBOX) || true; fi

.PHONY: test-docs
test-docs: DOCS_VERSION := $(shell grep -E ^VERSION $(MAKEFILE_ROOT_DIR)/Makefile | cut -d= -f2 | cut -d. -f1-2)
.PHONY:test-docs
test-docs: docsbox
docker run -i $(NOROOT) -v $$(pwd)/..:/src/content/$(DOCS_VERSION) $(DOCSBOX) \
docker run --platform=linux/amd64 -i $(NOROOT) -v $$(pwd)/..:/src/content $(DOCSBOX) \
/bin/sh -c "yarn markdown-lint-external-links"

# build-centos6-assets builds assets needed by CentOS 6 in a container.
.PHONY: build-centos6-assets
#
# Builds assets needed by CentOS 6 in a container.
#
.PHONY:build-centos6-assets
build-centos6-assets:
docker build -t buildbox-centos6-assets -f Dockerfile-centos6-assets .
docker run -v $$(pwd):/centos6.assets -it buildbox-centos6-assets cp /centos6-assets.tar.gz /centos6.assets

#
# Print the Go version used to build Teleport.
#
.PHONY:print-go-version
print-go-version:
@echo $(RUNTIME)

#
# Print the Rust version used to build Teleport.
#
.PHONY:print-rust-version
print-rust-version:
@echo $(RUST_VERSION)
27 changes: 20 additions & 7 deletions dronegen/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@

package main

import "fmt"
import (
"bytes"
"fmt"
"log"
"os/exec"
)

var (
triggerPullRequest = trigger{
Expand Down Expand Up @@ -70,18 +75,24 @@ var (
Name: "tmp-integration",
Path: "/tmp",
}

// TODO(gus): Set this from `make -C build.assets print-runtime-version` or similar rather
// than hardcoding it. Also remove the usage of RUNTIME as a pipeline-level environment variable
// (as support for these varies among Drone runners) and only set it for steps that need it.
goRuntime = value{raw: "go1.17.2"}
)

var goRuntime value

func init() {
v, err := exec.Command("make", "-C", "build.assets", "print-go-version").Output()
if err != nil {
log.Fatalf("could not get Go version: %v", err)
}
goRuntime = value{raw: string(bytes.TrimSpace(v))}
}

type buildType struct {
os string
arch string
fips bool
centos6 bool
centos7 bool
windowsUnsigned bool
}

Expand All @@ -108,11 +119,13 @@ func dockerVolumeRefs(v ...volumeRef) []volumeRef {
return append(v, volumeRefDocker)
}

// releaseMakefileTarget gets the correct Makefile target for a given arch/fips/centos6 combo
// releaseMakefileTarget gets the correct Makefile target for a given arch/fips/centos combo
func releaseMakefileTarget(b buildType) string {
makefileTarget := fmt.Sprintf("release-%s", b.arch)
if b.centos6 {
makefileTarget += "-centos6"
} else if b.centos7 {
makefileTarget += "-centos7"
}
if b.fips {
makefileTarget += "-fips"
Expand Down
Loading

0 comments on commit ffa69bc

Please sign in to comment.