diff --git a/deploy/packaging/argus_spruce.yaml b/.release/docker/argus_spruce.yaml similarity index 100% rename from deploy/packaging/argus_spruce.yaml rename to .release/docker/argus_spruce.yaml diff --git a/.release/docker/entrypoint.sh b/.release/docker/entrypoint.sh new file mode 100755 index 00000000..ae9aedad --- /dev/null +++ b/.release/docker/entrypoint.sh @@ -0,0 +1,37 @@ +#!/usr/bin/env sh +set -e + +# check arguments for an option that would cause /argus to stop +# return true if there is one +_want_help() { + local arg + for arg; do + case "$arg" in + -'?'|--help|-v) + return 0 + ;; + esac + done + return 1 +} + +_main() { + # if command starts with an option, prepend argus + if [ "${1:0:1}" = '-' ]; then + set -- /argus "$@" + fi + + # skip setup if they aren't running /argus or want an option that stops /argus + if [ "$1" = '/argus' ] && ! _want_help "$@"; then + echo "Entrypoint script for argus Server ${VERSION} started." + + if [ ! -s /etc/argus/argus.yaml ]; then + echo "Building out template for file" + /bin/spruce merge /tmp/argus_spruce.yaml > /etc/argus/argus.yaml + fi + fi + + exec "$@" +} + +_main "$@" diff --git a/Dockerfile b/Dockerfile index fba97b90..47225cfb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,19 +16,40 @@ RUN apk add --no-cache --no-progress \ libc-dev \ upx +# Download spruce here to eliminate the need for curl in the final image RUN mkdir -p /go/bin && \ - curl -o /go/bin/spruce https://github.com/geofffranks/spruce/releases/download/v1.29.0/spruce-linux-amd64 && \ + curl -L -o /go/bin/spruce https://github.com/geofffranks/spruce/releases/download/v1.29.0/spruce-linux-amd64 && \ chmod +x /go/bin/spruce + COPY . . + RUN make test release -FROM alpine:3.12.1 +########################## +# Build the final image. +########################## + +FROM alpine:latest + +# Copy over the standard things you'd expect. +COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ +COPY --from=builder /src/argus / +COPY --from=builder /src/.release/docker/entrypoint.sh / + +# Copy over spruce and the spruce template file used to make the actual configuration file. +COPY --from=builder /src/.release/docker/argus_spruce.yaml /tmp/argus_spruce.yaml +COPY --from=builder /go/bin/spruce /bin/ -COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ -COPY --from=builder /src/argus /src/argus.yaml /src/deploy/packaging/entrypoint.sh /go/bin/spruce /src/Dockerfile /src/NOTICE /src/LICENSE /src/CHANGELOG.md / -COPY --from=builder /src/deploy/packaging/argus_spruce.yaml /tmp/argus_spruce.yaml +# Include compliance details about the container and what it contains. +COPY --from=builder /src/Dockerfile \ + /src/NOTICE \ + /src/LICENSE \ + /src/CHANGELOG.md / -RUN mkdir /etc/argus/ && touch /etc/argus/argus.yaml && chmod 666 /etc/argus/argus.yaml +# Make the location for the configuration file that will be used. +RUN mkdir /etc/argus/ \ + && touch /etc/argus/argus.yaml \ + && chmod 666 /etc/argus/argus.yaml USER nobody diff --git a/Makefile b/Makefile index aa7616f9..72fc5ad8 100644 --- a/Makefile +++ b/Makefile @@ -2,10 +2,8 @@ DOCKER ?= docker -GO ?= go -GOFMT ?= $(GO)fmt APP := argus -DOCKER_ORG := xmidt +DOCKER_ORG := ghcr.io/xmidt-org VERSION ?= $(shell git describe --tag --always --dirty) PROGVER ?= $(shell git describe --tags `git rev-list --tags --max-count=1` | tail -1 | sed 's/v\(.*\)/\1/') @@ -16,21 +14,21 @@ GOBUILDFLAGS = -a -ldflags "-w -s -X 'main.BuildTime=$(BUILDTIME)' -X main.GitCo default: build generate: - $(GO) generate ./... - $(GO) install ./... + go generate ./... + go install ./... test: - $(GO) test -v -race -coverprofile=coverage.txt ./... - $(GO) test -v -race -json ./... > report.json + go test -v -race -coverprofile=coverage.txt ./... + go test -v -race -json ./... > report.json style: - ! $(GOFMT) -d $$(find . -path ./vendor -prune -o -name '*.go' -print) | grep '^' + ! gofmt -d $$(find . -path ./vendor -prune -o -name '*.go' -print) | grep '^' check: golangci-lint run -n | tee errors.txt build: - CGO_ENABLED=0 $(GO) build $(GOBUILDFLAGS) + CGO_ENABLED=0 go build $(GOBUILDFLAGS) release: build upx $(APP) @@ -42,8 +40,8 @@ docker: binaries: generate mkdir -p ./.ignore - CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 $(GO) build -o ./.ignore/$(APP)-$(PROGVER).darwin-amd64 -ldflags "-X 'main.BuildTime=$(BUILDTIME)' -X main.GitCommit=$(GITCOMMIT) -X main.Version=$(VERSION)" - CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GO) build -o ./.ignore/$(APP)-$(PROGVER).linux-amd64 -ldflags "-X 'main.BuildTime=$(BUILDTIME)' -X main.GitCommit=$(GITCOMMIT) -X main.Version=$(VERSION)" + CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -o ./.ignore/$(APP)-$(PROGVER).darwin-amd64 -ldflags "-X 'main.BuildTime=$(BUILDTIME)' -X main.GitCommit=$(GITCOMMIT) -X main.Version=$(VERSION)" + CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o ./.ignore/$(APP)-$(PROGVER).linux-amd64 -ldflags "-X 'main.BuildTime=$(BUILDTIME)' -X main.GitCommit=$(GITCOMMIT) -X main.Version=$(VERSION)" upx ./.ignore/$(APP)-$(PROGVER).darwin-amd64 upx ./.ignore/$(APP)-$(PROGVER).linux-amd64 diff --git a/conf/argus.env.example b/conf/argus.env.example deleted file mode 100644 index baaeed0b..00000000 --- a/conf/argus.env.example +++ /dev/null @@ -1,6 +0,0 @@ -#KERNEL_OPEN_FILES=95000 -#ULIMIT_OPEN_FILES=75000 -#NET_CORE_SOMAXCONN=1000 -#NET_IPV4_TCP_MAX_SYN_BACKLOG=1000 -#NET_IPV4_TCP_MEM="100000000 100000000 100000000" -DAEMON_COREFILE_LIMIT=unlimited diff --git a/conf/argus.service b/conf/argus.service deleted file mode 100644 index 44d43aad..00000000 --- a/conf/argus.service +++ /dev/null @@ -1,18 +0,0 @@ - -[Unit] -Description=The XMiDT API server for storing configuration. -After=network.target remote-fs.target nss-lookup.target - -[Service] -Type=simple -PIDFile=/run/argus.pid -ExecStartPre=/usr/bin/rm -f /run/argus.pid -ExecStart=/usr/bin/argus -ExecReload=/bin/kill -s HUP $MAINPID -TimeoutStopSec=10 -KillMode=process -PrivateTmp=true -Restart=always - -[Install] -WantedBy=multi-user.target diff --git a/deploy/Dockerfile b/deploy/Dockerfile deleted file mode 100644 index eee9acc3..00000000 --- a/deploy/Dockerfile +++ /dev/null @@ -1,48 +0,0 @@ -FROM docker.io/library/golang:1.14-alpine as builder - -LABEL MAINTAINER="Jack Murdock " - -WORKDIR /go/src/github.com/xmidt-org/argus - -ARG VERSION=unknown -ARG GITCOMMIT=unknown -ARG BUILDTIME=unknown - -ADD https://github.com/geofffranks/spruce/releases/download/v1.25.2/spruce-linux-amd64 /usr/local/bin/spruce -RUN chmod +x /usr/local/bin/spruce - -RUN apk add --no-cache --no-progress \ - ca-certificates \ - make \ - git \ - openssh \ - gcc \ - libc-dev \ - upx - -COPY . . -RUN make build - -FROM alpine:latest - -COPY --from=builder /etc/passwd /etc/passwd -COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ -COPY --from=builder /go/src/github.com/xmidt-org/argus/argus.yaml /argus.yaml -COPY --from=builder /go/src/github.com/xmidt-org/argus/argus /argus -COPY --from=builder /go/src/github.com/xmidt-org/argus/deploy/Dockerfile /go/src/github.com/xmidt-org/argus/NOTICE /go/src/github.com/xmidt-org/argus/LICENSE /go/src/github.com/xmidt-org/argus/CHANGELOG.md / -COPY --from=builder /go/src/github.com/xmidt-org/argus/deploy/packaging/entrypoint.sh /entrypoint.sh -COPY --from=builder /go/src/github.com/xmidt-org/argus/deploy/packaging/argus_spruce.yaml /tmp/argus_spruce.yaml -COPY --from=builder /usr/local/bin/spruce /spruce - -RUN mkdir /etc/argus/ && touch /etc/argus/argus.yaml && chmod 666 /etc/argus/argus.yaml - -USER nobody - -ENTRYPOINT ["/entrypoint.sh"] - -EXPOSE 6600 -EXPOSE 6601 -EXPOSE 6602 -EXPOSE 6603 - -CMD ["/argus"] diff --git a/deploy/docker_push b/deploy/docker_push deleted file mode 100755 index a270579a..00000000 --- a/deploy/docker_push +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/env sh - -# upload docker as $TRAVIS_TAG or latest -echo "$DOCKER_TOKEN" | docker login -u "$DOCKER_USERNAME" --password-stdin - -LATEST_TAG=$(git describe --tags `git rev-list --tags --max-count=1` | tail -1 | sed 's/v\(.*\)/\1/') -VERSION_TAG=$(echo "$TRAVIS_TAG" | sed 's/v\(.*\)/\1/') - -docker build --build-arg VERSION="$VERSION_TAG" --build-arg GITCOMMIT="`git rev-parse --short HEAD`" --build-arg BUILDTIME="`date -u '+%Y-%m-%d %H:%M:%S'`" -f ./deploy/Dockerfile -t xmidt/argus:$VERSION_TAG . - -docker push xmidt/argus:$VERSION_TAG - -if [[ "$VERSION_TAG" == "$LATEST_TAG" ]]; then - docker tag xmidt/argus:$VERSION_TAG xmidt/argus:latest - docker push xmidt/argus:latest -fi \ No newline at end of file diff --git a/deploy/packaging/argus.spec b/deploy/packaging/argus.spec deleted file mode 100644 index 700b2478..00000000 --- a/deploy/packaging/argus.spec +++ /dev/null @@ -1,90 +0,0 @@ -%define __os_install_post %{nil} -%define debug_package %{nil} - -Name: argus -Version: v{{{ git_tag_version }}} -Release: 1%{?dist} -Summary: The XMiDT API server for storing configuration. - -Vendor: Comcast -Packager: Comcast -Group: System Environment/Daemons -License: ASL 2.0 -URL: https://github.com/xmidt-org/argus -Source0: https://github.com/xmidt-org/%{name}/archive/%{version}.tar.gz - -Prefix: /opt -BuildRoot: %{_tmppath}/%{name} -BuildRequires: systemd -BuildRequires: golang >= 1.12 -BuildRequires: git - -%description -The XMiDT server for storing configuration like webhooks for caduceus. - -%prep -%setup -n %{name}-{{{ git_tag_version }}} - -%build -GOPROXY=https://proxy.golang.org go build -ldflags "-linkmode=external -X 'main.BuildTime=`date -u '+%c'`' -X main.GitCommit={{{ git_short_hash }}} -X main.Version=%{version}" -o %{name} . - -%install -echo rm -rf %{buildroot} -%{__install} -d %{buildroot}%{_bindir} -%{__install} -d %{buildroot}%{_initddir} -%{__install} -d %{buildroot}%{_sysconfdir}/%{name} -%{__install} -d %{buildroot}%{_localstatedir}/log/%{name} -%{__install} -d %{buildroot}%{_localstatedir}/run/%{name} -%{__install} -d %{buildroot}%{_unitdir} - -%{__install} -p %{name} %{buildroot}%{_bindir} -%{__install} -p conf/%{name}.service %{buildroot}%{_unitdir}/%{name}.service -%{__install} -p %{name}.yaml %{buildroot}%{_sysconfdir}/%{name}/%{name}.yaml - -%files -%defattr(644, root, root, 755) -%doc LICENSE CHANGELOG.md NOTICE - -%attr(755, root, root) %{_bindir}/%{name} - -%{_unitdir}/%{name}.service - -%dir %{_sysconfdir}/%{name} -%config %{_sysconfdir}/%{name}/%{name}.yaml - -%dir %attr(755, %{name}, %{name}) %{_localstatedir}/log/%{name} -%dir %attr(755, %{name}, %{name}) %{_localstatedir}/run/%{name} - -%pre -id %{name} >/dev/null 2>&1 -if [ $? != 0 ]; then - /usr/sbin/groupadd -r %{name} >/dev/null 2>&1 - /usr/sbin/useradd -d /var/run/%{name} -r -g %{name} %{name} >/dev/null 2>&1 -fi - -%post -if [ $1 = 1 ]; then - systemctl preset %{name}.service >/dev/null 2>&1 || : -fi - -%preun -if [ -e /etc/init.d/%{name} ]; then - systemctl --no-reload disable %{name}.service > /dev/null 2>&1 || : - systemctl stop %{name}.service > /dev/null 2>&1 || : -fi - -# If not an upgrade, then delete -if [ $1 = 0 ]; then - systemctl disable %{name}.service >/dev/null 2>&1 || : -fi - -%postun -# Do not remove anything if this is not an uninstall -if [ $1 = 0 ]; then - /usr/sbin/userdel -r %{name} >/dev/null 2>&1 - /usr/sbin/groupdel %{name} >/dev/null 2>&1 - # Ignore errors from above - true -fi - -%changelog diff --git a/deploy/packaging/entrypoint.sh b/deploy/packaging/entrypoint.sh deleted file mode 100755 index 08c17195..00000000 --- a/deploy/packaging/entrypoint.sh +++ /dev/null @@ -1,49 +0,0 @@ -#!/usr/bin/env sh - - -set -e - -# check to see if this file is being run or sourced from another script -_is_sourced() { - # https://unix.stackexchange.com/a/215279 - [ "${#FUNCNAME[@]}" -ge 2 ] \ - && [ "${FUNCNAME[0]}" = '_is_sourced' ] \ - && [ "${FUNCNAME[1]}" = 'source' ] -} - -# check arguments for an option that would cause /argus to stop -# return true if there is one -_want_help() { - local arg - for arg; do - case "$arg" in - -'?'|--help|-v) - return 0 - ;; - esac - done - return 1 -} - -_main() { - # if command starts with an option, prepend argus - if [ "${1:0:1}" = '-' ]; then - set -- /argus "$@" - fi - # skip setup if they aren't running /argus or want an option that stops /argus - if [ "$1" = '/argus' ] && ! _want_help "$@"; then - echo "Entrypoint script for argus Server ${VERSION} started." - - if [ ! -s /etc/argus/argus.yaml ]; then - echo "Building out template for file" - /spruce merge /argus.yaml /tmp/argus_spruce.yaml > /etc/argus/argus.yaml - fi - fi - - exec "$@" -} - -# If we are sourced from elsewhere, don't perform any further actions -if ! _is_sourced; then - _main "$@" -fi \ No newline at end of file diff --git a/rpkg.conf b/rpkg.conf deleted file mode 100644 index 957dc058..00000000 --- a/rpkg.conf +++ /dev/null @@ -1,2 +0,0 @@ -[rpkg] -user_macros = "${git_props:root}/rpkg.macros" diff --git a/rpkg.macros b/rpkg.macros deleted file mode 100644 index 0e49be8a..00000000 --- a/rpkg.macros +++ /dev/null @@ -1,23 +0,0 @@ -function git_short_hash { - short_hash="$(cached git_short_hash)" - - if [ -z "$short_hash" ]; then - short_hash="$(git rev-parse --short HEAD)" - fi - - output "$short_hash" -} - -function git_tag_version { - tag="$(cached git_tag_version)" - - if [ -z "$tag" ]; then - tag="$(git describe --tags --abbrev=0)" - fi - - # Remove the potential prefix of `v` - if [[ $tag =~ ^v[0-9].* ]]; then - tag="${tag:1}" - fi - output "$tag" -}