Skip to content

Commit

Permalink
Merge pull request #1 from CSSSR/update-dependencies
Browse files Browse the repository at this point in the history
Refactor test app
  • Loading branch information
verdel authored Jul 15, 2024
2 parents c9261c5 + 3f76e95 commit 36aefd2
Show file tree
Hide file tree
Showing 15 changed files with 169 additions and 16 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @cwarck @qtm @verdel @nitive
37 changes: 37 additions & 0 deletions .github/workflows/build-docker-image.yaml
Original file line number Diff line number Diff line change
@@ -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
19 changes: 19 additions & 0 deletions .github/workflows/lint-renovate.yaml
Original file line number Diff line number Diff line change
@@ -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
29 changes: 29 additions & 0 deletions .renovaterc
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
14 changes: 9 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
36 changes: 36 additions & 0 deletions app/.air.toml
Original file line number Diff line number Diff line change
@@ -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

4 changes: 4 additions & 0 deletions app/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*
!go.mod
!go.sum
!main.go
1 change: 1 addition & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
tmp-image
bin/
2 changes: 1 addition & 1 deletion app/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.14
FROM golang:1.22

WORKDIR /app

Expand Down
17 changes: 17 additions & 0 deletions app/Makefile
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 1 addition & 1 deletion app/go.mod
Original file line number Diff line number Diff line change
@@ -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
6 changes: 3 additions & 3 deletions app/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package main

import (
"fmt"
"io/ioutil"
"io"
"log"
"net/http"
"os"
Expand Down Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion chart/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ spec:
volumes:
- name: data
persistentVolumeClaim:
claimName: my-app
claimName: {{ .Release.Name }}
7 changes: 3 additions & 4 deletions chart/templates/ingress.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -13,6 +12,6 @@ spec:
pathType: Prefix
backend:
service:
name: my-app
port:
name: {{ .Release.Name }}
port:
number: 80

0 comments on commit 36aefd2

Please sign in to comment.