diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 00000000..0f019afe --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,69 @@ +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: + - uses: actions/checkout@v3 + - uses: actions/setup-go@v3 + with: + go-version: '1.17' + - name: golangci-lint + uses: golangci/golangci-lint-action@v2 + with: + version: v1.44 + test: + runs-on: ubuntu-latest + steps: + - 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: + 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_PASSWORD }} + - 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 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 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