Skip to content

Commit

Permalink
Merge pull request #7 from splitio/dev
Browse files Browse the repository at this point in the history
dev
  • Loading branch information
mredolatti authored Jun 30, 2023
2 parents 3750d31 + a009578 commit 7a2d364
Show file tree
Hide file tree
Showing 57 changed files with 5,041 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.git
.github
.gitignore
.netrc
splitd
splitcli
shared
testcfg
TODO

splitd.linux.*
splitd.darwin.*
90 changes: 90 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
name: ci
on:
pull_request:
branches:
- dev
push:
branches:
- dev

concurrency:
group: ${{ github.workflow }}-${{ github.event_name == 'push' && github.run_number || github.event.pull_request.number }}
cancel-in-progress: true

jobs:
test:
name: Run unit tests
runs-on: ubuntu-latest
steps:

- name: Set VERSION env
run: echo "VERSION=$(cat splitio/version.go | grep 'Version =' | awk '{print $3}' | tr -d '"')" >> $GITHUB_ENV

- name: Version validation
if: ${{ github.event_name == 'pull_request' }}
uses: mukunku/[email protected]
id: checkTag
with:
tag: ${{ env.VERSION }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Fail workflow if tag exists
if: ${{ github.event_name == 'pull_request' && steps.checkTag.outputs.exists == 'true' }}
uses: actions/[email protected]
with:
script: core.setFailed('[ERROR] Tag already exists.')

- name: Git tag
if: ${{ github.event_name == 'push' }}
uses: mathieudutour/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
custom_tag: ${{ env.VERSION }}
tag_prefix: ''

- name: Setup Go version
uses: actions/setup-go@v4
with:
go-version: '^1.19.1'

- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Build binaries for host machine
run: make splitd splitcli

- name: Cross build for GNU Linux & Darwin x amd64 & arm64
run: make binaries_release

- name: Run tests
run: make test

# - name: SonarQube Scan (Push)
# if: matrix.version == '8.2' && github.event_name == 'push'
# uses: SonarSource/[email protected]
# env:
# SONAR_TOKEN: ${{ secrets.SONARQUBE_TOKEN }}
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# with:
# projectBaseDir: .
# args: >
# -Dsonar.host.url=${{ secrets.SONARQUBE_HOST }}
# -Dsonar.projectVersion=${{ env.VERSION }}
#
# - name: SonarQube Scan (Pull Request)
# if: matrix.version == '8.2' && github.event_name == 'pull_request'
# uses: SonarSource/[email protected]
# env:
# SONAR_TOKEN: ${{ secrets.SONARQUBE_TOKEN }}
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# with:
# projectBaseDir: .
# args: >
# -Dsonar.host.url=${{ secrets.SONARQUBE_HOST }}
# -Dsonar.projectVersion=${{ env.VERSION }}
# -Dsonar.pullrequest.key=${{ github.event.pull_request.number }}
# -Dsonar.pullrequest.branch=${{ github.event.pull_request.head.ref }}
# -Dsonar.pullrequest.base=${{ github.event.pull_request.base.ref }}
52 changes: 52 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: docker

on:
push:
branches:
- dev
- main
pull_request:
branches:
- dev
- main

concurrency:
group: ${{ github.workflow }}-${{ github.event_name == 'push' && github.run_number || github.event.pull_request.number }}

jobs:
build-docker-image:
name: Build and push Docker image
runs-on: ubuntu-latest

steps:
- name: Login to Artifactory
if: ${{ github.event_name == 'push' }}
uses: docker/login-action@v2
with:
registry: splitio-docker.jfrog.io
username: ${{ secrets.ARTIFACTORY_DOCKER_USER }}
password: ${{ secrets.ARTIFACTORY_DOCKER_PASS }}

- name: Checkout code
uses: actions/checkout@v3

- name: Docker build and push
uses: docker/build-push-action@v4
with:
context: .
file: "infra/sidecar.Dockerfile"
push: ${{ github.event_name == 'push' }}
tags: splitio-docker.jfrog.io/${{ github.event.repository.name }}/sidecar:${{ github.sha }}

deploy:
name: Deploy to testing
if: ${{ github.event_name == 'push' }}
runs-on: ubuntu-latest
needs: build-docker-image
steps:
- name: Deploy to testing
run: |
curl --header "Content-Type: application/json" \
--request PUT \
--data '{ "service": "${{ github.event.repository.name }}", "environment": "testing", "tag": "${{ github.sha }}", "token": "${{ secrets.R2D2_SLACK_TOKEN_STAGE }}"}' \
https://r2d2.split-stage.io/deployment
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,12 @@

# Dependency directories (remove the comment below to include it)
# vendor/

/splitd
/splitcli
/splitd.yaml
testcfg
shared

splitd.darwin.*
splitd.linux.*
92 changes: 92 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
.PHONY: clean build test sidecar_image unit-tests entrypoint-test

# Setup defaults
GO ?=go
DOCKER ?= docker
SHELL = /usr/bin/env bash -o pipefail
PLATFORM ?=
VERSION := $(shell cat splitio/version.go | grep 'const Version' | sed 's/const Version = //' | tr -d '"')

GO_FILES := $(shell find . -name "*.go") go.sum

default: help

## generate go.sum from go.mod
go.sum: go.mod
go mod tidy

## delete built assets
clean:
rm -Rf splitcli \
splitd \
splitd.linux.amd64.$(VERSION).bin \
splitd.darwin.amd64.$(VERSION).bin \
splitd.linux.arm.$(VERSION).bin \
splitd.darwin.arm.$(VERSION).bin

## build binaries for this platform
build: splitd splitcli

## run all tests
test: unit-tests entrypoint-test

## run go unit tests
unit-tests:
$(GO) test ./... -count=1 -race

## run bash entrypoint tests
entrypoint-test:
bash infra/test/test_entrypoint.sh

## build splitd for local machine
splitd: $(GO_FILES)
go build -o splitd cmd/splitd/main.go

## build splitcli for local machine
splitcli: $(GO_FILES)
go build -o splitcli cmd/splitcli/main.go

## build docker images for sidecar
images_release: # entrypoints
$(DOCKER) build $(platform_str) -t splitsoftware/splitd-sidecar:latest -t splitsoftware/splitd-sidecar:$(VERSION) -f infra/sidecar.Dockerfile .
@echo "Image created. Make sure everything works ok, and then run the following commands to push them."
@echo "$(DOCKER) push splitsoftware/splitd-sidecar:latest"
@echo "$(DOCKER) push splitsoftware/splitd-sidecar:$(VERSION)"

## build release for binaires
binaries_release: splitd.linux.amd64.$(VERSION).bin splitd.darwin.amd64.$(VERSION).bin splitd.linux.arm.$(VERSION).bin splitd.darwin.arm.$(VERSION).bin


splitd.linux.amd64.$(VERSION).bin: $(GO_FILES)
GOARCH=amd64 GOOS=linux $(GO) build -o $@ cmd/splitd/main.go

splitd.darwin.amd64.$(VERSION).bin: $(GO_FILES)
GOARCH=amd64 GOOS=darwin $(GO) build -o $@ cmd/splitd/main.go

splitd.linux.arm.$(VERSION).bin: $(GO_FILES)
GOARCH=arm64 GOOS=linux $(GO) build -o $@ cmd/splitd/main.go

splitd.darwin.arm.$(VERSION).bin: $(GO_FILES)
GOARCH=arm64 GOOS=darwin $(GO) build -o $@ cmd/splitd/main.go

binaries_release: splitd

# helper macros
platform_str = $(if $(PLATFORM),--platform=$(PLATFORM),)

# Help target borrowed from: https://docs.cloudposse.com/reference/best-practices/make-best-practices/
## This help screen
help:
@printf "Available targets:\n\n"
@awk '/^[a-zA-Z\-\_0-9%:\\]+/ { \
helpMessage = match(lastLine, /^## (.*)/); \
if (helpMessage) { \
helpCommand = $$1; \
helpMessage = substr(lastLine, RSTART + 3, RLENGTH); \
gsub("\\\\", "", helpCommand); \
gsub(":+$$", "", helpCommand); \
printf " \x1b[32;01m%-35s\x1b[0m %s\n", helpCommand, helpMessage; \
} \
} \
{ lastLine = $$0 }' $(MAKEFILE_LIST) | sort -u
@printf "\n"
8 changes: 8 additions & 0 deletions TODO
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
- move serialization logic from service to link
- keep track of open conns
- set appropriate timeouts
- msgpack - array serialization of maps
- logging
- testing
- admin endpoints?
- healthcheck & harakiri?
Loading

0 comments on commit 7a2d364

Please sign in to comment.