From 79cd204692bf2be0a37e77cc46e634831fe154a2 Mon Sep 17 00:00:00 2001 From: Vadim Aleksandrov Date: Mon, 15 Jul 2024 16:25:35 +0300 Subject: [PATCH 01/11] chore(docker): update go image version in dockerfile --- app/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Dockerfile b/app/Dockerfile index 7752b02..418375e 100644 --- a/app/Dockerfile +++ b/app/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.14 +FROM golang:1.22 WORKDIR /app From d3132478c5151e5f6e732867c633ec94d9d357e1 Mon Sep 17 00:00:00 2001 From: Vadim Aleksandrov Date: Mon, 15 Jul 2024 16:26:23 +0300 Subject: [PATCH 02/11] chore(docker): add .dockerignore --- app/.dockerignore | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 app/.dockerignore diff --git a/app/.dockerignore b/app/.dockerignore new file mode 100644 index 0000000..dce5eb0 --- /dev/null +++ b/app/.dockerignore @@ -0,0 +1,4 @@ +* +!go.mod +!go.sum +!main.go From 9bcc9d02a0ae5936aa9585175fe3f87d3458775d Mon Sep 17 00:00:00 2001 From: Vadim Aleksandrov Date: Mon, 15 Jul 2024 16:26:49 +0300 Subject: [PATCH 03/11] chore: add air tool for hot reload app --- app/.air.toml | 36 ++++++++++++++++++++++++++++++++++++ app/.gitignore | 1 + 2 files changed, 37 insertions(+) create mode 100644 app/.air.toml diff --git a/app/.air.toml b/app/.air.toml new file mode 100644 index 0000000..14411a2 --- /dev/null +++ b/app/.air.toml @@ -0,0 +1,36 @@ +root = '.' +tmp_dir = 'bin' + +[build] +cmd = 'go build -o bin/app main.go' +bin = './bin/app' +full_bin = '' +args_bin = [] +include_ext = ['go'] +exclude_dir = ['bin', 'tests'] +include_dir = [] +exclude_file = [] +exclude_regex = ['_test.go'] +exclude_unchanged = false +follow_symlink = false +delay = 1000 +stop_on_error = true +send_interrupt = false +kill_delay = 0 + +[color] +main = 'magenta' +watcher = 'cyan' +build = 'yellow' +runner = 'green' +app = '' + +[log] +time = false + +[misc] +clean_on_exit = true + +[screen] +clear_on_rebuild = false + diff --git a/app/.gitignore b/app/.gitignore index 2706aa8..9936971 100644 --- a/app/.gitignore +++ b/app/.gitignore @@ -1 +1,2 @@ tmp-image +bin/ \ No newline at end of file From f6338abfd10ae0a486c800c8794b3b656cdf1b1f Mon Sep 17 00:00:00 2001 From: Vadim Aleksandrov Date: Mon, 15 Jul 2024 16:27:43 +0300 Subject: [PATCH 04/11] chore(golang): update go dependencies --- app/go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/go.mod b/app/go.mod index d7d5384..da56295 100644 --- a/app/go.mod +++ b/app/go.mod @@ -1,5 +1,5 @@ module github.com/CSSSR/my-app -go 1.14 +go 1.22 require github.com/logrusorgru/aurora v2.0.3+incompatible From ce6189685a43c30986c89355f404ea943f02431f Mon Sep 17 00:00:00 2001 From: Vadim Aleksandrov Date: Mon, 15 Jul 2024 16:28:11 +0300 Subject: [PATCH 05/11] chore(app): migrate from ioutil to io --- app/main.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/main.go b/app/main.go index 0636883..16505e7 100644 --- a/app/main.go +++ b/app/main.go @@ -2,7 +2,7 @@ package main import ( "fmt" - "io/ioutil" + "io" "log" "net/http" "os" @@ -36,12 +36,12 @@ func uploadFile(w http.ResponseWriter, r *http.Request) { } defer file.Close() - fileBytes, err := ioutil.ReadAll(file) + fileBytes, err := io.ReadAll(file) if err != nil { log.Fatalf("Error reading file %v", err) } - ioutil.WriteFile(config.ImagePath, fileBytes, os.FileMode(0600)) + os.WriteFile(config.ImagePath, fileBytes, os.FileMode(0600)) log.Println(aurora.Cyan("Successfully Uploaded File")) fmt.Fprintf(w, "Successfully Uploaded File\n") From 9a83963cfb7c5eebff2f0ca98e3ff1013a1e1366 Mon Sep 17 00:00:00 2001 From: Vadim Aleksandrov Date: Mon, 15 Jul 2024 16:28:47 +0300 Subject: [PATCH 06/11] chore(github-workflow): add build and publish docker image workflow --- .github/workflows/build-docker-image.yaml | 37 +++++++++++++++++++++++ app/Makefile | 17 +++++++++++ 2 files changed, 54 insertions(+) create mode 100644 .github/workflows/build-docker-image.yaml create mode 100644 app/Makefile diff --git a/.github/workflows/build-docker-image.yaml b/.github/workflows/build-docker-image.yaml new file mode 100644 index 0000000..e1655ab --- /dev/null +++ b/.github/workflows/build-docker-image.yaml @@ -0,0 +1,37 @@ +name: Docker image build +on: + push: + branches: [master] + paths: + - app/** + pull_request: + paths: + - app/** + +jobs: + build-images: + name: Build docker image + runs-on: ubuntu-latest + timeout-minutes: 10 + steps: + - uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Build test-app + run: make build + working-directory: app + + - name: Login to Quay + if: github.event_name == 'push' + uses: docker/login-action@v3 + with: + registry: quay.csssr.cloud + username: csssr+github_devops_test_app + password: ${{ secrets.QUAY_REGISTRY_PASSWORD }} + + - name: Publish test-app + run: make publish + if: github.event_name == 'push' + working-directory: app diff --git a/app/Makefile b/app/Makefile new file mode 100644 index 0000000..e9215ad --- /dev/null +++ b/app/Makefile @@ -0,0 +1,17 @@ +.PHONY: start build publish + +export GOBIN=${CURDIR}/bin + +version ?= master + +$(GOBIN)/air: + go install github.com/air-verse/air@latest + +start: $(GOBIN)/air + air + +build: + docker build . --tag quay.csssr.cloud/csssr/test-app:$(version) + +publish: + docker push quay.csssr.cloud/csssr/test-app:$(version) From d768b1ec10a36cc275912318df2ae8eec32977dc Mon Sep 17 00:00:00 2001 From: Vadim Aleksandrov Date: Mon, 15 Jul 2024 16:29:29 +0300 Subject: [PATCH 07/11] chore(makefile): refactor main makefile --- Makefile | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index cca359a..42f810d 100644 --- a/Makefile +++ b/Makefile @@ -1,11 +1,15 @@ +.PHONY: publish-app start-app deploy + +HELM=$(shell which helm3 2>/dev/null || which helm) BRANCH ?= master -build-app: - docker build app --tag quay.csssr.cloud/csssr/test-app:$(BRANCH) - docker push quay.csssr.cloud/csssr/test-app:$(BRANCH) +start-app: + $(MAKE) -C app start -HELM ?= helm3 +publish-app: + $(MAKE) -C app build version=$(BRANCH) + $(MAKE) -C app publish version=$(BRANCH) deploy: - $(HELM) upgrade --install my-app-$(BRANCH) chart --set image.tag=$(BRANCH) --set ingress.host=$(BRANCH).my-app.com + $(HELM) upgrade --install my-app-$(BRANCH) chart --set image.tag=$(BRANCH) --set ingress.host=$(BRANCH).csssr.cloud From ce8eeabf9eb819bb4327bc59f94f6ce5e8e7df7f Mon Sep 17 00:00:00 2001 From: Vadim Aleksandrov Date: Mon, 15 Jul 2024 16:29:58 +0300 Subject: [PATCH 08/11] chore(renovate): add renovate configuration and lint github workflow --- .github/workflows/lint-renovate.yaml | 19 ++++++++++++++++++ .renovaterc | 29 ++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 .github/workflows/lint-renovate.yaml create mode 100644 .renovaterc diff --git a/.github/workflows/lint-renovate.yaml b/.github/workflows/lint-renovate.yaml new file mode 100644 index 0000000..852f86d --- /dev/null +++ b/.github/workflows/lint-renovate.yaml @@ -0,0 +1,19 @@ +name: Lint renovate configuration + +on: + push: + branches: [master] + paths: + - .renovaterc + - ".github/workflows/lint-renovate.yaml" + pull_request: + paths: + - .renovaterc + - ".github/workflows/lint-renovate.yaml" +jobs: + validate: + runs-on: ubuntu-latest + timeout-minutes: 3 + steps: + - uses: actions/checkout@v4 + - uses: suzuki-shunsuke/github-action-renovate-config-validator@v1.0.1 diff --git a/.renovaterc b/.renovaterc new file mode 100644 index 0000000..62e5730 --- /dev/null +++ b/.renovaterc @@ -0,0 +1,29 @@ +{ + "$schema": "https://docs.renovatebot.com/renovate-schema.json", + "extends": [ + "config:recommended", + ":disableRateLimiting", + ":disableVulnerabilityAlerts" + ], + "labels": [ + "dependencies" + ], + "postUpdateOptions": [ + "gomodTidy", + "gomodUpdateImportPaths" + ], + "reviewersFromCodeOwners": true, + "enabledManagers": [ + "gomod", + "dockerfile", + "github-actions" + ], + "packageRules": [ + { + "matchDatasources": [ + "golang-version" + ], + "rangeStrategy": "bump" + } + ] +} From f1ae4600dcab367e73bed3ac9d2f6ac99e1e4963 Mon Sep 17 00:00:00 2001 From: Vadim Aleksandrov Date: Mon, 15 Jul 2024 16:30:23 +0300 Subject: [PATCH 09/11] chore(github): add CODEOWNERS --- .github/CODEOWNERS | 1 + 1 file changed, 1 insertion(+) create mode 100644 .github/CODEOWNERS diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 0000000..ee94fe6 --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1 @@ +* @cwarck @qtm @verdel @nitive From 343a53830835db013e3bf2cdc74925828d3a0215 Mon Sep 17 00:00:00 2001 From: Vadim Aleksandrov Date: Mon, 15 Jul 2024 16:30:36 +0300 Subject: [PATCH 10/11] chore(reamde): update info in README.md --- README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8485803..7c55109 100644 --- a/README.md +++ b/README.md @@ -22,12 +22,18 @@ curl http://my-app.com/image -o image.jpg - 100% uptime - Возможность делать несколько релизов для разных веток в один неймспейс (для тестирования) +## Локальный запуск приложения + +```sh +make start-app +``` + ## Деплой Сборка ```sh -make build BRANCH=master +make publish-app BRANCH=master ``` Деплой helm чарта (используется helm 3) From 3f76e95a5171db084ac2ea2e7e60bb0866407607 Mon Sep 17 00:00:00 2001 From: Vadim Aleksandrov Date: Mon, 15 Jul 2024 16:31:02 +0300 Subject: [PATCH 11/11] fix(chart): fix claimName and service name --- chart/templates/deployment.yaml | 2 +- chart/templates/ingress.yaml | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/chart/templates/deployment.yaml b/chart/templates/deployment.yaml index aeab116..fb2e3b7 100644 --- a/chart/templates/deployment.yaml +++ b/chart/templates/deployment.yaml @@ -29,4 +29,4 @@ spec: volumes: - name: data persistentVolumeClaim: - claimName: my-app + claimName: {{ .Release.Name }} diff --git a/chart/templates/ingress.yaml b/chart/templates/ingress.yaml index fa00b16..6c89ba8 100644 --- a/chart/templates/ingress.yaml +++ b/chart/templates/ingress.yaml @@ -2,9 +2,8 @@ apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: {{ .Release.Name }} - annotations: - kubernetes.io/ingress.class: nginx spec: + ingressClassName: nginx rules: - host: {{ .Values.ingress.host }} http: @@ -13,6 +12,6 @@ spec: pathType: Prefix backend: service: - name: my-app - port: + name: {{ .Release.Name }} + port: number: 80