From 3411fe75fde33820d685815c93b8d6efa8e77616 Mon Sep 17 00:00:00 2001 From: Ben Coleman Date: Sun, 24 Jan 2021 10:43:24 +0000 Subject: [PATCH] fighting the war against ALL CAPS --- .github/workflows/ci-build.yml | 46 ++++++++++++++++++ .github/workflows/docker-ci-build.yml | 41 ---------------- .github/workflows/gofmt-action.sh | 21 --------- .golangci.yaml | 1 + CONTRIBUTING.md | 68 +++++++++++++++++++++++---- _config.yml | 6 +-- build/Dockerfile | 14 +++--- makefile | 68 +++++++++++---------------- web/client/package.json | 6 +-- 9 files changed, 143 insertions(+), 128 deletions(-) create mode 100644 .github/workflows/ci-build.yml delete mode 100644 .github/workflows/docker-ci-build.yml delete mode 100644 .github/workflows/gofmt-action.sh diff --git a/.github/workflows/ci-build.yml b/.github/workflows/ci-build.yml new file mode 100644 index 0000000..9634e07 --- /dev/null +++ b/.github/workflows/ci-build.yml @@ -0,0 +1,46 @@ +name: CI Build + +# This is a generic CI pipeline that assumes project is to be built as a container image +# Note. CI build only builds 'latest' image, not a versioned release +# Note. REGISTRY_PASSWORD must be set and change the IMAGE_NAME + +on: + push: + branches: [master] + pull_request: + branches: [master] + +env: + IMAGE_REG: ghcr.io + IMAGE_NAME: kubeview + IMAGE_TAG: latest + +jobs: + ci-build: + name: Code Check & CI build + runs-on: ubuntu-latest + + steps: + # Checkout code from repo + - name: Checkout repo + uses: actions/checkout@v2 + + # Ensures Go is configured properly + - uses: actions/setup-go@v2 + with: + go-version: '^1.15.7' + + # Validate code + - name: Check code for linting and format errors + run: make lint + + # Build image + - name: Build the container image + run: make image IMAGE_REPO=$GITHUB_ACTOR/$IMAGE_NAME + + # Only when pushing to default branch (e.g. master or main), then push image to registry + - name: Push to container registry + if: github.ref == 'refs/heads/master' && github.event_name == 'push' + run: | + echo ${{ secrets.REGISTRY_PASSWORD }} | docker login $IMAGE_REG -u $GITHUB_ACTOR --password-stdin + make push IMAGE_REPO=$GITHUB_ACTOR/$IMAGE_NAME diff --git a/.github/workflows/docker-ci-build.yml b/.github/workflows/docker-ci-build.yml deleted file mode 100644 index 35631af..0000000 --- a/.github/workflows/docker-ci-build.yml +++ /dev/null @@ -1,41 +0,0 @@ -name: Build Dockerhub Image - -on: - push: - branches: [master] - pull_request: - branches: [master] - -# Note. CI build only builds 'latest' image, not the semver release -env: - IMAGE_NAME: kubeview - IMAGE_TAG: latest - -jobs: - ci-build: - name: Code Check & CI build - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v1 - - uses: actions/setup-go@v2 - with: - go-version: '^1.15.7' - - # Validate code - - name: Check code for linting and format errors - run: make format lint - #bash .github/workflows/gofmt-action.sh cmd/server - - # Build image - - name: Build the Docker image - run: make image BUILD_INFO="GitHub CI build $GITHUB_RUN_ID, of $GITHUB_REF on $(date -I)" - #run: docker build . --file ./build/Dockerfile --build-arg buildInfo="GitHub CI build $GITHUB_RUN_ID, of $GITHUB_REF on $(date -I)" --tag ghcr.io/$GITHUB_ACTOR/$IMAGE_NAME:$IMAGE_TAG - - # Only when pushing to master push to GHCR - - name: Push to Github registry - if: github.ref == 'refs/heads/master' - run: | - echo ${{ secrets.CR_PAT }} | docker login ghcr.io -u $GITHUB_ACTOR --password-stdin - make push - #docker push ghcr.io/$GITHUB_ACTOR/$IMAGE_NAME:$IMAGE_TAG diff --git a/.github/workflows/gofmt-action.sh b/.github/workflows/gofmt-action.sh deleted file mode 100644 index e19521a..0000000 --- a/.github/workflows/gofmt-action.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash - -# -# Hacky bash script to run gofmt and report any files with problems -# Will show up as GitHub Action annotations in the workflow -# Ben Coleman -# -set -e -out=$(gofmt -l $1) -linecount=$(echo "$out" | sed '/^\s*$/d' | wc -l) - -if (( $linecount > 0 )); then - while IFS= read -r line; do - echo "::error::gofmt error in file: $line check logs for details" - done <<< "$out" - - # Print actual diff and error details - gofmt -d $1 - - exit 1 -fi \ No newline at end of file diff --git a/.golangci.yaml b/.golangci.yaml index c26b659..ef76c8f 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -4,6 +4,7 @@ linters-settings: linters: enable: - golint + - gofmt issues: include: - EXC0002 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index cb92737..3a38870 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,16 +1,64 @@ -# Contributing Guidance -Hello! Thanks for taking an interest in my project/repo. +# Welcome -Contributions to this project are welcome of course, otherwise I wouldn't have put it on GitHub 😃 however there's a few things I'd like to point out: +Hello! Thanks for taking an interest in this project and code :) + +Contributions to this project are welcome of course, otherwise it wouldn't reside on GitHub 😃 however there's a few things to be aware of: - This is a personal project, it is not maintained by a team or group. -- The code here is not production grade, you won't see many unit tests or other 'robust' practices in the code base. -- I might have written things a certain way either by ignorance of a better/faster/cooler approach, maybe by design or just simple pragmatism. -- It might take me a long time (weeks) to reply to issues or review PRs, I have a day job & I might not have looked at the code for a while. +- It might take a long time for the maintainer(s) to reply to issues or review PRs, they will have have a day jobs & might not have looked at the code for a while. +- The code here is likely to not be bullet proof & production grade, there might be a lack of unit tests or other practices missing from the code base. + +# Contributing + +There's several ways of contributing to this project, and effort has been made to make this as easy and transparent as possible, whether it's: + +- Reporting a bug +- Discussing the current state of the code +- Submitting a fix +- Proposing new features +- Becoming a maintainer + +## All code changes happen though pull requests (PRs) + +Pull requests are the best way to propose changes to the codebase (using the standard [Github Flow](https://guides.github.com/introduction/flow/index.html)). + +Some PR guidance: + +- Please keep PRs small and focused on a single feature or change, with discreet commits. Use multiple PRs if need be. +- If you're thinking of adding a feature via a PR please create an issue first where it can be discussed. + +High level steps: + +1. Fork the repo and create your branch from `master` or `main`. +2. If you've changed APIs, update the documentation. +3. Ensure the test suite (if any) passes (run `make lint`). +4. Make sure your code lints (run `make lint`). +5. Issue that pull request! + +## Any contributions you make will be under the MIT Software License + +In short, when you submit code changes, your submissions are understood to be under the same [MIT License](http://choosealicense.com/licenses/mit/) that covers the project. + +## Report bugs using Github's issues + +This project uses GitHub issues to track public bugs. Report a bug by [opening a new issue](./issues/new/choose) + +## Write bug reports with detail, background, and sample code + +**Great Bug Reports** tend to have: + +- A quick summary and/or background +- Steps to reproduce + - Be specific! + - Give sample code if you can. Even if it's a snippet +- What you expected would happen +- What actually happens +- Notes (possibly including why you think this might be happening, or stuff you tried that didn't work) + +## Use a consistent coding style -A few pointers +Run `make lint-fix` in order to format the code fix any formatting & linting issues that might be present. A [Prettier](https://prettier.io/) configuration file is included -- If you're thinking of adding a feature via a PR please create an issue first and we can discuss it. -- Please keep PRs small and focused on a single feature or change, with discreet commits. Multiple PRs if need be. +# References -Thanks! \ No newline at end of file +This document was heavily adapted from the open-source contribution guidelines found in [this gist](https://gist.github.com/briandk/3d2e8b3ec8daf5a27a62) diff --git a/_config.yml b/_config.yml index 57c0be9..262c0e5 100644 --- a/_config.yml +++ b/_config.yml @@ -1,9 +1,9 @@ # # This file might sound important but... -# It is only used by the hosting on GitHub Pages, it has no other importance to the Smilr project +# It is only used by the hosting on GitHub Pages, it has no other importance to the project # -title: "KubeView" +title: 'KubeView' remote_theme: benc-uk/theme-msdark favicon: /web/client/src/assets/logo.png buttons: @@ -18,4 +18,4 @@ buttons: href: /web/client - b3: text: Deployment - href: /deployments/helm/ \ No newline at end of file + href: /deployments/helm/ diff --git a/build/Dockerfile b/build/Dockerfile index a53910d..c72bd99 100644 --- a/build/Dockerfile +++ b/build/Dockerfile @@ -16,9 +16,7 @@ COPY ${sourceDir}/.eslintrc.js . COPY ${sourceDir}/public ./public COPY ${sourceDir}/src ./src -# Run ESLint checks -RUN npm run lint -# Now main Vue CLI build & bundle, this will output to ./dist +# Carry out Vue CLI build & bundle, this will output to ./dist RUN npm run build # ================================================================================================ @@ -26,9 +24,9 @@ RUN npm run build # ================================================================================================ FROM golang:1.15-alpine as go-build WORKDIR /build -ARG goPackage="github.com/benc-uk/kubeview/cmd/server" -ARG version="0.0.0" -ARG buildInfo="Not set" +ARG GO_PACKAGE="github.com/benc-uk/kubeview/cmd/server" +ARG VERSION="0.0.0" +ARG BUILD_INFO="Not set" ENV PORT 8000 @@ -47,9 +45,9 @@ COPY cmd/ ./cmd # Disabling cgo results in a fully static binary that can run without C libs # Also inject version and build details RUN GO111MODULE=on CGO_ENABLED=0 GOOS=linux go build \ - -ldflags "-X main.version=$version -X 'main.buildInfo=$buildInfo'" \ + -ldflags "-X main.version=$VERSION -X 'main.buildInfo=$BUILD_INFO'" \ -o server \ - $goPackage + $GO_PACKAGE # ================================================================================================ # === Stage 3: Bundle server exe and Vue dist in runtime image =================================== diff --git a/makefile b/makefile index 65e324d..0d22d77 100644 --- a/makefile +++ b/makefile @@ -8,62 +8,49 @@ VERSION := 0.1.20 BUILD_INFO := Manual build from makefile # Most likely want to override these when calling `make image` -DOCKER_REG ?= ghcr.io -DOCKER_REPO ?= benc-uk/kubeview -DOCKER_TAG ?= latest -DOCKER_PREFIX := $(DOCKER_REG)/$(DOCKER_REPO) +IMAGE_REG ?= ghcr.io +IMAGE_REPO ?= benc-uk/kubeview +IMAGE_TAG ?= latest +IMAGE_PREFIX := $(IMAGE_REG)/$(IMAGE_REPO) + +.PHONY: help image push build-frontend build-server lint lint-fix +.DEFAULT_GOAL := help -.PHONY: image push build-frontend build-server lint lint-ci format format-ci ################################################################################ -# Lint - check everything +help: ## This help message :) + @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' + + ################################################################################ -lint: $(FRONTEND_DIR)/node_modules +lint: $(FRONTEND_DIR)/node_modules ## Lint & format, will not fix but sets exit code on error go get github.com/golangci/golangci-lint/cmd/golangci-lint golangci-lint run $(SERVER_DIR)/... - cd $(FRONTEND_DIR); npm run lint-ci + cd $(FRONTEND_DIR); npm run lint + ################################################################################ -# Lint - will try to fix errors & modify code -################################################################################ -lint-fix: $(FRONTEND_DIR)/node_modules +lint-fix: $(FRONTEND_DIR)/node_modules ## Lint & format, will try to fix errors and modify code go get github.com/golangci/golangci-lint/cmd/golangci-lint golangci-lint run $(SERVER_DIR)/... --fix - cd $(FRONTEND_DIR); npm run lint + cd $(FRONTEND_DIR); npm run lint-fix -################################################################################ -# Format - check everything -################################################################################ -format: $(FRONTEND_DIR)/node_modules - @test -z `gofmt -l $(SERVER_DIR)` || (gofmt -d $(SERVER_DIR) && exit 1) - cd $(FRONTEND_DIR); npm run format-ci ################################################################################ -# Format - will try to fix errors & modify code -################################################################################ -format-fix: $(FRONTEND_DIR)/node_modules - gofmt -w $(SERVER_DIR) - cd $(FRONTEND_DIR); npm run format - -################################################################################ -# Build combined Docker image (API server plus frontend) -################################################################################ -image: +image: ## Build combined container image (API server plus frontend) docker build --file ./build/Dockerfile \ - --build-arg buildInfo="$(BUILD_INFO)" \ - --build-arg version="$(VERSION)" \ - --tag $(DOCKER_REG)/$(DOCKER_REPO):$(DOCKER_TAG) . + --build-arg BUILD_INFO="$(BUILD_INFO)" \ + --build-arg VERSION="$(VERSION)" \ + --tag $(IMAGE_PREFIX):$(IMAGE_TAG) . -################################################################################ -# Push combined Docker image -################################################################################ -push: - docker push $(DOCKER_REG)/$(DOCKER_REPO):$(DOCKER_TAG) ################################################################################ -# Build & bundle Frontend / Vue.js +push: ## Push combined container image + docker push $(IMAGE_PREFIX):$(IMAGE_TAG) + + ################################################################################ -build-frontend: $(FRONTEND_DIR)/node_modules +build-frontend: $(FRONTEND_DIR)/node_modules ## Build & bundle Frontend / Vue.js cd $(FRONTEND_DIR); npm run build $(FRONTEND_DIR)/node_modules: $(FRONTEND_DIR)/package.json @@ -73,10 +60,9 @@ $(FRONTEND_DIR)/node_modules: $(FRONTEND_DIR)/package.json $(FRONTEND_DIR)/package.json: @echo "package.json was modified" + ################################################################################ -# Build server -################################################################################ -build-server: +build-server: ## Build Go API server GO111MODULE=on CGO_ENABLED=0 GOOS=linux go build \ -ldflags "-X main.version=\"$(VERSION)\" -X 'main.buildInfo=\"$(BUILD_INFO)\"'" \ -o server $(SERVER_DIR)/... \ No newline at end of file diff --git a/web/client/package.json b/web/client/package.json index 6106343..2eb87f2 100644 --- a/web/client/package.json +++ b/web/client/package.json @@ -8,10 +8,8 @@ "scripts": { "serve": "vue-cli-service serve", "build": "vue-cli-service build", - "lint": "vue-cli-service lint", - "lint-ci": "vue-cli-service lint --no-fix", - "format": "prettier --write src", - "format-ci": "prettier --check src" + "lint-fix": "vue-cli-service lint && prettier --write src", + "lint": "vue-cli-service lint --no-fix && prettier --check src" }, "dependencies": { "bootstrap-vue": "^2.21.2",