Skip to content

Commit

Permalink
Merge pull request #59 from ns1labs/feature/ci-containers
Browse files Browse the repository at this point in the history
improved CI, push containers to docker hub
  • Loading branch information
weyrick authored Jul 23, 2021
2 parents 64934bf + 71e8396 commit c5f914b
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 32 deletions.
79 changes: 65 additions & 14 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
name: Go

on:
push:
branches: [ develop ]
workflow_dispatch:
pull_request:
branches: [ develop ]
branches:
- develop
push:
branches:
- develop

jobs:

Expand All @@ -18,20 +21,68 @@ jobs:
with:
go-version: 1.15

- name: Build orb agent
- name: Build services (go build only)
run: make services

- name: Build orb agent (go build only)
run: make agent

- name: Build fleet manager
run: make fleet
- name: Go unit tests
run: make test

- name: Build policy manager
run: make policies
- name: Build UI
run: make ui

- name: Build sink manager
run: make sinks
package:
needs: build
runs-on: ubuntu-latest
# if this is a push into one of our main branches (rather than just a pull request), we will also package
if: github.event_name != 'pull_request'

- name: Build prometheus sink
run: make prom-sink
steps:
- uses: actions/checkout@v2

- name: Test
run: make test
- name: Get branch name
shell: bash
run: echo "BRANCH_NAME=$(echo ${GITHUB_REF#refs/heads/} | tr / -)" >> $GITHUB_ENV

- name: Debug branch name
run: echo ${{ env.BRANCH_NAME }}

- name: Generate ref tag (main)
if: ${{ env.BRANCH_NAME == 'main' }}
run: |
echo "REF_TAG=latest" >> $GITHUB_ENV
- name: Generate ref tag (develop)
if: ${{ env.BRANCH_NAME == 'develop' }}
run: |
echo "REF_TAG=develop" >> $GITHUB_ENV
- name: Debug ref tag
run: echo ${{ env.REF_TAG }}

- name: Login to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build service containers
run: make dockers

- name: Push service containers
run: |
docker push ns1labs/orb-fleet:${{ env.REF_TAG }}
docker push ns1labs/orb-policies:${{ env.REF_TAG }}
docker push ns1labs/orb-sinks:${{ env.REF_TAG }}
docker push ns1labs/orb-prom-sink:${{ env.REF_TAG }}
# agent

- name: Build + push orb-ui
env:
IMAGE_NAME: ns1labs/orb-ui
run: |
make ui
docker push ${{ env.IMAGE_NAME }}:${{ env.REF_TAG }}
32 changes: 14 additions & 18 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,23 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/. */

MF_DOCKER_IMAGE_NAME_PREFIX ?= orb
REF_TAG ?= latest
DOCKER_IMAGE_NAME_PREFIX ?= orb
DOCKERHUB_REPO = ns1labs
BUILD_DIR = build
SERVICES = fleet policies sinks prom-sink agent
SERVICES = fleet policies sinks prom-sink
DOCKERS = $(addprefix docker_,$(SERVICES))
DOCKERS_DEV = $(addprefix docker_dev_,$(SERVICES))
CGO_ENABLED ?= 0
GOARCH ?= amd64

define compile_service
CGO_ENABLED=$(CGO_ENABLED) GOOS=$(GOOS) GOARCH=$(GOARCH) GOARM=$(GOARM) go build -mod=mod -ldflags "-s -w" -o ${BUILD_DIR}/$(MF_DOCKER_IMAGE_NAME_PREFIX)-$(1) cmd/$(1)/main.go
CGO_ENABLED=$(CGO_ENABLED) GOOS=$(GOOS) GOARCH=$(GOARCH) GOARM=$(GOARM) go build -mod=mod -ldflags "-s -w" -o ${BUILD_DIR}/$(DOCKER_IMAGE_NAME_PREFIX)-$(1) cmd/$(1)/main.go
endef

define compile_service_linux
$(eval svc=$(subst docker_dev_,,$(1)))
CGO_ENABLED=$(CGO_ENABLED) GOOS=linux GOARCH=$(GOARCH) GOARM=$(GOARM) go build -mod=mod -ldflags "-s -w" -o ${BUILD_DIR}/$(MF_DOCKER_IMAGE_NAME_PREFIX)-$(svc) cmd/$(svc)/main.go
CGO_ENABLED=$(CGO_ENABLED) GOOS=linux GOARCH=$(GOARCH) GOARM=$(GOARM) go build -mod=mod -ldflags "-s -w" -o ${BUILD_DIR}/$(DOCKER_IMAGE_NAME_PREFIX)-$(svc) cmd/$(svc)/main.go
endef

define make_docker
Expand All @@ -32,7 +33,7 @@ define make_docker
--build-arg SVC=$(svc) \
--build-arg GOARCH=$(GOARCH) \
--build-arg GOARM=$(GOARM) \
--tag=$(DOCKERHUB_REPO)/$(MF_DOCKER_IMAGE_NAME_PREFIX)-$(svc) \
--tag=$(DOCKERHUB_REPO)/$(DOCKER_IMAGE_NAME_PREFIX)-$(svc):$(REF_TAG) \
-f docker/Dockerfile .
endef

Expand All @@ -42,13 +43,13 @@ define make_docker_dev
docker build \
--no-cache \
--build-arg SVC=$(svc) \
--tag=$(DOCKERHUB_REPO)/$(MF_DOCKER_IMAGE_NAME_PREFIX)-$(svc) \
--tag=$(DOCKERHUB_REPO)/$(DOCKER_IMAGE_NAME_PREFIX)-$(svc):$(REF_TAG) \
-f docker/Dockerfile.dev ./build
endef

all: $(SERVICES)

.PHONY: all $(SERVICES) dockers dockers_dev latest release ui
.PHONY: all $(SERVICES) dockers dockers_dev ui services agent

clean:
rm -rf ${BUILD_DIR}
Expand All @@ -60,12 +61,9 @@ cleandocker:

ifdef pv
# Remove unused volumes
docker volume ls -f name=$(MF_DOCKER_IMAGE_NAME_PREFIX) -f dangling=true -q | xargs -r docker volume rm
docker volume ls -f name=$(DOCKER_IMAGE_NAME_PREFIX) -f dangling=true -q | xargs -r docker volume rm
endif

install:
cp ${BUILD_DIR}/* $(GOBIN)

test:
go test -mod=mod -race -count 1 -tags test $(shell go list ./... | grep -v 'cmd')

Expand All @@ -82,19 +80,17 @@ $(DOCKERS_DEV):
$(call compile_service_linux,$(@))
$(call make_docker_dev,$(@))

services: $(SERVICES)
dockers: $(DOCKERS)
dockers_dev: $(DOCKERS_DEV)

define docker_push
for svc in $(SERVICES); do \
docker push $(DOCKERHUB_REPO)/$(MF_DOCKER_IMAGE_NAME_PREFIX)-$$svc:$(1); \
done
endef

run:
docker-compose -f docker/docker-compose.yml up -d

agent:
$(call compile_service,agent)

ui:
cd ui/ && docker build --tag=ns1labs/orb-ui -f docker/Dockerfile .
cd ui/ && docker build --tag=$(DOCKERHUB_REPO)/$(DOCKER_IMAGE_NAME_PREFIX)-ui:$(REF_TAG) -f docker/Dockerfile .


0 comments on commit c5f914b

Please sign in to comment.