From 2e9b9177c1d4c67e7fc2e46ac2287873908f52c6 Mon Sep 17 00:00:00 2001 From: Adam Vollrath Date: Wed, 30 Mar 2022 14:46:24 -0500 Subject: [PATCH 1/6] Draft of GitHub Actions for this repo --- .github/workflows/main.yml | 63 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 00000000..067826d0 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,63 @@ +name: Test, Lint, Build, and Publish Image +on: + push: + branches: + - qa + - develop + - main + pull_request: + types: [opened,synchronize,reopened] + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Run lint + run: make lint + test: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Run tests + run: make test + build-and-push-some-branches: + runs-on: ubuntu-latest + needs: + - lint + - test + if: ${{ github.ref_name == 'main' || github.ref_name == 'qa' || github.ref_name == 'develop' || github.event_name == 'pull_request' }} + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + - name: Login to DockerHub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Docker metadata + id: meta + uses: docker/metadata-action@v3 + with: + images: uffizzi/controller + tags: | + type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) }} + type=ref,event=branch,enable=${{ github.ref_name == 'qa' || github.ref_name == 'develop' }} + type=ref,event=pr + - name: Build and Push Image to Docker Hub + uses: docker/build-push-action@v2 + with: + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + - name: Update Docker Hub Description for Default Branch + uses: peter-evans/dockerhub-description@v2.4.3 + if: ${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) }} + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_PASSWORD }} + repository: uffizzi/controller From 63307647b029f134f2f0ce0c9bcbdd75fdd2a17b Mon Sep 17 00:00:00 2001 From: Adam Vollrath Date: Wed, 30 Mar 2022 14:51:13 -0500 Subject: [PATCH 2/6] Use GitHub's `setup-go` Action. --- .github/workflows/main.yml | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 067826d0..079eebc4 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -12,15 +12,19 @@ jobs: lint: runs-on: ubuntu-latest steps: - - name: Checkout - uses: actions/checkout@v2 + - uses: actions/checkout@v3 + - uses: actions/setup-go@v3 + with: + go-version: '1.17' - name: Run lint run: make lint test: runs-on: ubuntu-latest steps: - - name: Checkout - uses: actions/checkout@v2 + - uses: actions/checkout@v3 + - uses: actions/setup-go@v3 + with: + go-version: '1.17' - name: Run tests run: make test build-and-push-some-branches: From c3d03633895cc4516577a013db23bd8058814ba7 Mon Sep 17 00:00:00 2001 From: Adam Vollrath Date: Wed, 30 Mar 2022 15:00:57 -0500 Subject: [PATCH 3/6] Remove some CI/CD config that's no longer relevant. --- Makefile | 88 ------------------------------------------- docker-compose.ci.yml | 4 -- 2 files changed, 92 deletions(-) delete mode 100644 docker-compose.ci.yml diff --git a/Makefile b/Makefile index b7939c51..66596658 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,4 @@ APP_NAME=uffizzi -CI_PROJECT_ID="sapient-flare-242118" -GCP_REGION=us-central1-c - -CI_REPO_URL="gcr.io/${CI_PROJECT_ID}" -GCP_REPO_URL="gcr.io/${GCP_PROJECT_ID}" CONTROLLER_IMAGE_NAME="${APP_NAME}-controller" CONTROLLER_IMAGE="${CI_REPO_URL}/${CONTROLLER_IMAGE_NAME}" @@ -48,88 +43,5 @@ fix_lint: test: ENV=test go test ./... -# CI targets - -image_names: - export CONTROLLER_IMAGE=${CONTROLLER_IMAGE}:${VERSION} - -ci_registry_login: - echo ${CI_SERVICE_ACCOUNT_KEY} | docker login -u _json_key --password-stdin https://gcr.io - -registry_login: - cat ${SERVICE_ACCOUNT_KEY} | docker login -u _json_key --password-stdin https://gcr.io - -build_controller: - docker pull "${CONTROLLER_IMAGE}:${CI_COMMIT_REF_SLUG}" || true - docker pull "${CONTROLLER_IMAGE}:latest" || true - docker build \ - --cache-from "${CONTROLLER_IMAGE}:${CI_COMMIT_REF_SLUG}" \ - --cache-from "${CONTROLLER_IMAGE}:latest" \ - --build-arg SENTRY_RELEASE=${SHORT_VERSION} \ - -t ${CONTROLLER_IMAGE}:${VERSION} \ - -t "${CONTROLLER_IMAGE}:${CI_COMMIT_REF_SLUG}" \ - -t ${CONTROLLER_IMAGE}:${SHORT_VERSION} \ - -t ${CONTROLLER_IMAGE}:latest \ - . - -push_controller: - docker push ${CONTROLLER_IMAGE}:${VERSION} - docker push ${CONTROLLER_IMAGE}:${SHORT_VERSION} - docker push ${CONTROLLER_IMAGE}:${CI_COMMIT_REF_SLUG} || true - docker push ${CONTROLLER_IMAGE}:latest - -push_gcp_controller: - docker push ${GCP_CONTROLLER_IMAGE}:${VERSION} - docker push ${GCP_CONTROLLER_IMAGE}:${SHORT_VERSION} - docker push ${GCP_CONTROLLER_IMAGE}:${CI_COMMIT_REF_SLUG} || true - docker push ${GCP_CONTROLLER_IMAGE}:latest - -sentry_environment: - export SENTRY_ORG=${APP_NAME}-cloud - export SENTRY_PROJECT=${APP_NAME}-controller - -sentry_release: - sentry-cli releases new ${SHORT_VERSION} - sentry-cli releases set-commits --auto ${SHORT_VERSION} - sentry-cli releases finalize ${SHORT_VERSION} - sentry-cli releases deploys ${SHORT_VERSION} new -e ${ENV} - -pull_ci_image: - docker pull ${CONTROLLER_IMAGE}:${VERSION} - docker pull ${CONTROLLER_IMAGE}:${SHORT_VERSION} - docker pull ${CONTROLLER_IMAGE}:${CI_COMMIT_REF_SLUG} || true - docker pull ${CONTROLLER_IMAGE}:latest - -tag_image: - docker tag ${CONTROLLER_IMAGE}:${SHORT_VERSION} ${GCP_CONTROLLER_IMAGE}:${VERSION} - docker tag ${CONTROLLER_IMAGE}:${SHORT_VERSION} ${GCP_CONTROLLER_IMAGE}:${SHORT_VERSION} - docker tag ${CONTROLLER_IMAGE}:${SHORT_VERSION} ${GCP_CONTROLLER_IMAGE}:${CI_COMMIT_REF_SLUG} || true - docker tag ${CONTROLLER_IMAGE}:${SHORT_VERSION} ${GCP_CONTROLLER_IMAGE}:latest - -update_image: pull_ci_image tag_image registry_login push_gcp_controller - -setup_gke_kube: - gcloud auth activate-service-account --key-file ${SERVICE_ACCOUNT_KEY} - gcloud config set project ${GCP_PROJECT_ID} - gcloud container clusters get-credentials ${CLUSTER_NAME} --zone ${GCP_REGION} - -setup_eks_kube: - aws eks --region ${AWS_DEFAULT_REGION} update-kubeconfig --name ${CLUSTER_NAME} - -aks_login: - az login --service-principal --username ${AZURE_USERNAME} --password ${AZURE_SERVICE_PRINCIPAL_KEY} --tenant ${AZURE_TENANT} - -setup_aks_kube: aks_login - az aks get-credentials --resource-group ${CLUSTER_NAME} --name ${CLUSTER_NAME} - -update_gke_controller_service: setup_gke_kube - kubectl set image deployment/uffizzi-controller -n uffizzi-controller controller=${GCP_CONTROLLER_IMAGE}:${SHORT_VERSION} - -update_eks_controller_service: setup_eks_kube - kubectl set image deployment/uffizzi-controller -n uffizzi-controller controller=${GCP_CONTROLLER_IMAGE}:${SHORT_VERSION} - -update_aks_controller_service: setup_aks_kube - kubectl set image deployment/uffizzi-controller -n uffizzi-controller controller=${GCP_CONTROLLER_IMAGE}:${SHORT_VERSION} - generate_docs: cmd/swag init -g cmd/controller/main.go --generatedTime=false --markdownFiles docs/markdown diff --git a/docker-compose.ci.yml b/docker-compose.ci.yml deleted file mode 100644 index afa79de8..00000000 --- a/docker-compose.ci.yml +++ /dev/null @@ -1,4 +0,0 @@ -version: '3' -services: - controller: - image: $CONTROLLER_IMAGE From 189564bcd1ceba82c3c1677edf2e538a9b20b761 Mon Sep 17 00:00:00 2001 From: Adam Vollrath Date: Wed, 30 Mar 2022 15:05:39 -0500 Subject: [PATCH 4/6] Use the `golangci-lint` GitHub Action. --- .github/workflows/main.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 079eebc4..ae7eba4f 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -16,8 +16,10 @@ jobs: - uses: actions/setup-go@v3 with: go-version: '1.17' - - name: Run lint - run: make lint + - name: golangci-lint + uses: golangci/golangci-lint-action@v2 + with: + version: v1.44 test: runs-on: ubuntu-latest steps: From 5bbfe441b4fca337e333327f59b11c03023cd4e1 Mon Sep 17 00:00:00 2001 From: Adam Vollrath Date: Wed, 30 Mar 2022 15:09:24 -0500 Subject: [PATCH 5/6] lint older code. --- internal/http/resources.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/http/resources.go b/internal/http/resources.go index 7baae78b..d14334da 100644 --- a/internal/http/resources.go +++ b/internal/http/resources.go @@ -22,7 +22,7 @@ type ApplyResourceRequest struct { func (h *Handlers) handleApplyResource(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) - deploymentID, err := strconv.ParseUint(vars["deploymentId"], 10, 64) + deploymentID, err := strconv.ParseUint(vars["deploymentId"], 10, 64) //nolint: gomnd if err != nil { handleError(err, w, r) return From 5a261adfa3598abd68f98ff6da995bd4c26f896a Mon Sep 17 00:00:00 2001 From: Adam Vollrath Date: Wed, 30 Mar 2022 15:13:57 -0500 Subject: [PATCH 6/6] Use Docker Hub password instead of token. --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index ae7eba4f..0f019afe 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -44,7 +44,7 @@ jobs: uses: docker/login-action@v1 with: username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} + password: ${{ secrets.DOCKERHUB_PASSWORD }} - name: Docker metadata id: meta uses: docker/metadata-action@v3