Skip to content

Commit

Permalink
feat: initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
hazcod committed Jan 13, 2021
0 parents commit 60a6c35
Show file tree
Hide file tree
Showing 64 changed files with 12,222 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.github/
.git/
.DS_Store
.gitignore
Makefile
25 changes: 25 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
version: 2

updates:
-
package-ecosystem: github-actions
directory: "/"
target-branch: dev
schedule:
interval: daily
time: '04:00'
open-pull-requests-limit: 10
commit-message:
prefix: "chore"
include: "scope"
-
package-ecosystem: docker
directory: "/kubernetes/docker/"
target-branch: dev
schedule:
interval: daily
time: "04:00"
open-pull-requests-limit: 10
commit-message:
prefix: "feat"
include: "scope"
Empty file added .github/golangci.yml
Empty file.
41 changes: 41 additions & 0 deletions .github/workflows/building.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Builds

on: [pull_request]

jobs:

build-go:
name: Compile Go
runs-on: ubuntu-latest
steps:
-
name: Setup go
uses: actions/setup-go@v2
-
name: Download Go modules
run: go mod download
-
name: Compile Go code
run: go build -o /dev/null ./cmd/api/

build-dev:
name: Development
runs-on: ubuntu-latest
steps:
-
name: Checkout code
uses: actions/checkout@v2
-
name: Docker build
run: make build STAGE="dev"

build-prd:
name: Production
runs-on: ubuntu-latest
steps:
-
name: Checkout code
uses: actions/checkout@v2
-
name: Docker build
run: make build STAGE="prd"
15 changes: 15 additions & 0 deletions .github/workflows/cleanup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Cleanup

on:
push:

jobs:

cleanup:
runs-on: ubuntu-latest
steps:
-
if: "!startsWith(github.ref, 'refs/tags/') && github.ref != 'refs/heads/master'"
uses: rokroskar/workflow-run-cleanup-action@v0.3.0
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
31 changes: 31 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# disabled since it's enterprise-only feature :(
name: "CodeQL"

on:
pull_request:
branches: [master]
schedule:
- cron: '0 11 * * 2'

jobs:

analyze:
name: Analyze
runs-on: ubuntu-latest

steps:
-
name: Checkout repository
uses: actions/checkout@v2
-
name: Initialize CodeQL
uses: github/codeql-action/init@v1
with:
languages: javascript
# languages: go, javascript, csharp, python, cpp, java
-
name: Autobuild
uses: github/codeql-action/autobuild@v1
-
name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
73 changes: 73 additions & 0 deletions .github/workflows/linting.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: Linting

on: [pull_request]

jobs:

# k8slint:
# name: Kubernetes
# runs-on: ubuntu-latest
# steps:
# -
# uses: actions/checkout@v2
# -
# uses: makocchi-git/actions-k8s-manifests-validate-kubeval@v1.0.1
# with:
# files: kubernetes/helm/templates/
# token: ${{ secrets.GITHUB_TOKEN }}

golangci:
name: Go
runs-on: ubuntu-latest
steps:
-
uses: actions/checkout@v2
-
name: golangci-lint
uses: reviewdog/action-golangci-lint@master
with:
github_token: ${{ secrets.github_token }}
golangci_lint_flags: "--config=.github/golangci.yml"

codespell:
name: Language
runs-on: ubuntu-latest
steps:
-
name: Check out code.
uses: actions/checkout@v2
-
name: codespell
uses: plettich/action-codespell@v0.3
with:
github_token: ${{ secrets.github_token }}

yamllint:
name: YAML
runs-on: ubuntu-latest
steps:
-
name: Check out code.
uses: actions/checkout@v2
-
name: yamllint
uses: reviewdog/action-yamllint@v1
with:
github_token: ${{ secrets.github_token }}
reporter: github-pr-review
yamllint_flags: 'docker/'

hadolint:
name: Dockerfiles
runs-on: ubuntu-latest
steps:
-
name: Check out code.
uses: actions/checkout@v2
-
name: hadolint
uses: reviewdog/action-hadolint@v1
with:
github_token: ${{ secrets.github_token }}
reporter: github-pr-review
hadolint_flags: 'docker/'
108 changes: 108 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
name: Release

on:
push:
branches: [master]

jobs:

release:
name: Container Image & Chart
runs-on: ubuntu-latest
steps:
-
uses: actions/checkout@v2
-
uses: go-semantic-release/action@v1.11.2
id: version
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
-
name: Check for changes
uses: andymckay/cancel-action@0.2
if: ${{ steps.version.outputs.version == '' }}
with:
token: ${{ secrets.GITHUB_TOKEN }}
-
name: Docker login
if: ${{ steps.version.outputs.version != '' }}
env:
USER: hazcod
REGISTRY: ghcr.io
run: |
echo "We are going to push for release '${{ steps.version.outputs.version }}'"
echo "${{ secrets.PACKAGE_TOKEN }}" | docker login -u "${USER}" --password-stdin "${REGISTRY}"
-
name: Docker build
if: ${{ steps.version.outputs.version != '' }}
run: |
make build STAGE="prd" RELEASE="${{ steps.version.outputs.version }}"
-
name: Docker push
if: ${{ steps.version.outputs.version != '' }}
run: |
images=$(make getimages)
for image in ${images[@]}; do
echo "Pushing image ${image}"
docker push "${image}"
done
-
name: Install helm
if: ${{ steps.version.outputs.version != '' }}
uses: azure/setup-helm@v1
-
name: Checkout branch for Chart repo
if: ${{ steps.version.outputs.version != '' }}
env:
STATIC_BRANCH: helmrepo
run: |
git config --local user.email "action@github.com"
git config --local user.name "${GITHUB_ACTOR}"
git fetch
git checkout "${STATIC_BRANCH}"
-
name: Package Helm Charts
if: ${{ steps.version.outputs.version != '' }}
env:
HELM_REPO: .
K8S_DIR: kubernetes/helm/
run: |
helm package "${K8S_DIR}" -d "${HELM_REPO}" --version "${{ steps.version.outputs.version }}"
-
name: Index Helm Charts
if: ${{ steps.version.outputs.version != '' }}
env:
HELM_REPO: .
run: |
helm repo index --url "${HELM_REPO_URL}" "${HELM_REPO}"
-
name: Push to GitHub Pages
if: ${{ steps.version.outputs.version != '' }}
env:
STATIC_BRANCH: helmrepo
HELM_REPO: .
run: |
git add "${HELM_REPO}"
git commit -m "chore: add helm charts for release ${{ steps.version.outputs.version }}"
git push --set-upstream origin "${STATIC_BRANCH}"
# --------------------------------------------------------------------------------
-
name: Rollback Release
if: ${{ failure() && steps.version.outputs.version != '' }}
uses: author/action-rollback@stable
with:
tag: ${{ steps.version.outputs.version }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}


cleanpackages:
runs-on: ubuntu-latest
steps:
-
name: clean frontend package versions
uses: actions/delete-package-versions@v1
with:
package-name: "iron-chart-go/iron-chart-go"
num-old-versions-to-delete: 5
num-most-recent-versions-to-keep: 5
43 changes: 43 additions & 0 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Tests

on: [pull_request]

jobs:

gotest:
name: Go Tests
runs-on: ubuntu-latest
steps:
-
name: Setup go
uses: actions/setup-go@v2
-
name: Download Go modules
run: go mod download
-
name: Run Go Tests
run: go test -v $(go list ./... | grep -v /vendor/)

helmtest:
name: E2E Testing
runs-on: ubuntu-latest
steps:
-
uses: actions/checkout@v2
-
name: Set up Helm
uses: azure/setup-helm@v1
-
uses: actions/setup-python@v2
-
name: Set up chart-testing
uses: helm/chart-testing-action@v2.0.1
-
name: Run chart-testing (lint)
run: ct lint --all --chart-dirs kubernetes/helm/
-
name: Create kind cluster
uses: helm/kind-action@v1.1.0
-
name: Run chart-testing (install)
run: ct install --all --chart-dirs kubernetes/helm/
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
generated/
.git/
.DS_Store
resources/
generated/
34 changes: 34 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

NAMESPACE=""
REGISTRY="ghcr.io/ironpeakservices/iron-chart-go"
NAME="iron-chart-go"
STAGE="dev"
RELEASE=$(STAGE)

K8S_DIR="kubernetes"
DOCKER_DIR=$(K8S_DIR)/docker
CHART_DIR=$(K8S_DIR)/helm

all: build up logs

clean:
helm uninstall --namespace $(NAMESPACE) $(NAME) || true

build:
@if [[ $(STAGE) == "prd" && $(RELEASE) == "prd" ]]; then echo "You must specify a release for production builds."; exit 1; fi;
DOCKER_BUILDKIT=1 docker build -t $(REGISTRY)/$(NAME):$(RELEASE) -f $(DOCKER_DIR)/$(STAGE).Dockerfile .

up:
kubectl create namespace $(NAMESPACE) || true
helm upgrade --debug --wait --install --namespace $(NAMESPACE) --values $(K8S_DIR)/$(STAGE).yaml --set "devWorkingDirectory=$(shell pwd)" $(NAME) $(CHART_DIR)
helm test --logs --namespace $(NAMESPACE) $(NAME)
kubectl get pods --namespace $(NAMESPACE)

logs:
kubectl logs --namespace $(NAMESPACE) -f -l app=$(NAME)

open:
open "http://127.0.0.1:$$(kubectl get service -n $(NAMESPACE) | grep $(NAME) | grep -Eo '\d+\:\d+' | cut -d ':' -f 1)/"

getimages:
@docker images --no-trunc "$(REGISTRY)/$(NAME)" | grep -v '^REPOSITORY' | awk '{print $$1":"$$2}'
Loading

0 comments on commit 60a6c35

Please sign in to comment.