| -rw-r--r-- | .github/workflows/build-and-deploy-prod.yml | 103 | ||||
| -rw-r--r-- | .github/workflows/build-and-deploy-stage.yml | 104 | ||||
| -rw-r--r-- | .gitignore | 2 | ||||
| -rw-r--r-- | Jenkinsfile | 4 | ||||
| -rw-r--r-- | deploy/playbook.yml | 4 | ||||
| -rw-r--r-- | internal/router/basic-handler.go | 2 | ||||
| -rw-r--r-- | internal/router/handlers/api-v1-blog-search.go | 4 | ||||
| -rw-r--r-- | internal/router/handlers/api-v1-email-send-verification-code.go | 4 | ||||
| -rw-r--r-- | internal/router/handlers/api-v1-email-verify.go | 4 | ||||
| -rw-r--r-- | internal/router/handlers/api-v1-like-put.go | 4 | ||||
| -rw-r--r-- | internal/router/handlers/api-v1-subs-put.go | 4 | ||||
| -rw-r--r-- | internal/router/router.go | 4 |
12 files changed, 19 insertions, 224 deletions
diff --git a/.github/workflows/build-and-deploy-prod.yml b/.github/workflows/build-and-deploy-prod.yml deleted file mode 100644 index fc44571..0000000 --- a/.github/workflows/build-and-deploy-prod.yml +++ /dev/null @@ -1,103 +0,0 @@ -name: Docker image building and publishing onto Production -on: - push: - tags: - - "*" -jobs: - build-and-push: - if: github.repository == 'SayaAndy/saya-today-web' - runs-on: ubuntu-latest - environment: Production - permissions: - packages: write - steps: - - name: Checkout - uses: actions/checkout@v6 - - - name: Generate output.css with tailwindcss - uses: ZoeyVid/tailwindcss-update@main - with: - input: static/input.css - output: static/output.css - params: "--minify" - - - name: Set up QEMU - uses: docker/setup-qemu-action@v4 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v4 - - - name: Login to GitHub Container Registry - uses: docker/login-action@v4 - with: - registry: ghcr.io - username: ${{ github.repository_owner }} - password: ${{ secrets.GHCR_TOKEN }} - - - name: Build and push - uses: docker/build-push-action@v7 - with: - context: . - file: ./Dockerfile - push: true - cache-from: type=gha - cache-to: type=gha,mode=max - tags: | - ghcr.io/sayaandy/saya-today-web:latest - ghcr.io/sayaandy/saya-today-web:stable - ghcr.io/sayaandy/saya-today-web:${{ github.ref_name }} - - deploy: - if: github.repository == 'SayaAndy/saya-today-web' - runs-on: ubuntu-latest - environment: Production - needs: [build-and-push] - container: - image: ghcr.io/ansible/community-ansible-dev-tools:v26.4.6 - options: --user root - steps: - - name: Checkout - uses: actions/checkout@v6 - - - name: Install community.docker collection - run: ansible-galaxy collection install community.docker - - - name: Set up SSH connection for uz.saya.casa - run: | - mkdir -p ~/.ssh - (cat <<EOF - ${{ secrets.SVC_GITHUB_PK }} - EOF - ) > ~/.ssh/id_ed25519 - chmod 600 ~/.ssh/id_ed25519 - sed -i 's/\r$//' ~/.ssh/id_ed25519 - ssh-keyscan -H uz.saya.casa >> ~/.ssh/known_hosts - - - name: Test SSH connection - run: | - ssh -o ConnectTimeout=10 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i ~/.ssh/id_ed25519 svc_github@uz.saya.casa "echo 'SSH connection successful'" - - - name: Run Ansible playbook - env: - ANSIBLE_HOST_KEY_CHECKING: "False" - working-directory: ./deploy - run: | - ansible-playbook \ - playbook.yml \ - -i inventory.yml \ - -l prod \ - --private-key ~/.ssh/id_ed25519 \ - -u svc_github \ - -e saya_today_web_auth_salt="${{ secrets.AUTH_SALT }}" \ - -e saya_today_web_s3_access_key_id="${{ secrets.S3_ACCESS_KEY_ID }}" \ - -e saya_today_web_s3_secret_access_key="${{ secrets.S3_SECRET_ACCESS_KEY }}" \ - -e saya_today_web_environment=prod \ - -e saya_today_web_tag=${{ github.ref_name }} \ - -e saya_today_web_mail_salt="${{ secrets.MAIL_SALT }}" \ - -e saya_today_web_mail_host="${{ secrets.MAIL_HOST }}" \ - -e saya_today_web_mail_address="${{ secrets.MAIL_ADDRESS }}" \ - -e saya_today_web_mail_username="${{ secrets.MAIL_USERNAME }}" \ - -e saya_today_web_mail_password="${{ secrets.MAIL_PASSWORD }}" \ - -e saya_today_google_site_verification="${{ secrets.GOOGLE_SITE_VERIFICATION }}" \ - -e saya_today_yandex_verification="${{ secrets.YANDEX_VERIFICATION }}" \ - -e saya_today_bing_verification="${{ secrets.BING_VERIFICATION }}" diff --git a/.github/workflows/build-and-deploy-stage.yml b/.github/workflows/build-and-deploy-stage.yml deleted file mode 100644 index ce4a1fb..0000000 --- a/.github/workflows/build-and-deploy-stage.yml +++ /dev/null @@ -1,104 +0,0 @@ -name: Docker image building and publishing onto Stage -on: - push: - branches: [stage] -jobs: - build-and-push: - if: github.repository == 'SayaAndy/saya-today-web' - runs-on: ubuntu-latest - environment: Stage - permissions: - packages: write - outputs: - sha_short: ${{ steps.ghss_vars.outputs.sha_short }} - steps: - - name: Checkout - uses: actions/checkout@v6 - - - name: Generate output.css with tailwindcss - uses: ZoeyVid/tailwindcss-update@main - with: - input: static/input.css - output: static/output.css - params: "--minify" - - - name: Set up QEMU - uses: docker/setup-qemu-action@v4 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v4 - - - name: Login to GitHub Container Registry - uses: docker/login-action@v4 - with: - registry: ghcr.io - username: ${{ github.repository_owner }} - password: ${{ secrets.GHCR_TOKEN }} - - - name: Set github short sha - id: ghss_vars - run: echo "sha_short=${GITHUB_SHA::7}" >> $GITHUB_OUTPUT - - - name: Build and push - uses: docker/build-push-action@v7 - with: - context: . - file: ./Dockerfile - push: true - cache-from: type=gha - cache-to: type=gha,mode=max - tags: | - ghcr.io/sayaandy/saya-today-web:latest - ghcr.io/sayaandy/saya-today-web:commit-${{ steps.ghss_vars.outputs.sha_short }} - - deploy: - if: github.repository == 'SayaAndy/saya-today-web' - runs-on: ubuntu-latest - environment: Stage - needs: [build-and-push] - container: - image: ghcr.io/ansible/community-ansible-dev-tools:v26.4.6 - options: --user root - steps: - - name: Checkout - uses: actions/checkout@v6 - - - name: Install community.docker collection - run: ansible-galaxy collection install community.docker - - - name: Set up SSH connection for uz.saya.casa - run: | - mkdir -p ~/.ssh - (cat <<EOF - ${{ secrets.SVC_GITHUB_PK }} - EOF - ) > ~/.ssh/id_ed25519 - chmod 600 ~/.ssh/id_ed25519 - sed -i 's/\r$//' ~/.ssh/id_ed25519 - ssh-keyscan -H uz.saya.casa >> ~/.ssh/known_hosts - - - name: Test SSH connection - run: | - ssh -o ConnectTimeout=10 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i ~/.ssh/id_ed25519 svc_github@uz.saya.casa "echo 'SSH connection successful'" - - - name: Run Ansible playbook - env: - ANSIBLE_HOST_KEY_CHECKING: "False" - working-directory: ./deploy - run: | - ansible-playbook \ - playbook.yml \ - -i inventory.yml \ - -l stage \ - --private-key ~/.ssh/id_ed25519 \ - -u svc_github \ - -e saya_today_web_auth_salt="${{ secrets.AUTH_SALT }}" \ - -e saya_today_web_s3_access_key_id="${{ secrets.S3_ACCESS_KEY_ID }}" \ - -e saya_today_web_s3_secret_access_key="${{ secrets.S3_SECRET_ACCESS_KEY }}" \ - -e saya_today_web_environment=stage \ - -e saya_today_web_tag=commit-${{ needs.build-and-push.outputs.sha_short }} \ - -e saya_today_web_mail_salt="${{ secrets.MAIL_SALT }}" \ - -e saya_today_web_mail_host="${{ secrets.MAIL_HOST }}" \ - -e saya_today_web_mail_address="${{ secrets.MAIL_ADDRESS }}" \ - -e saya_today_web_mail_username="${{ secrets.MAIL_USERNAME }}" \ - -e saya_today_web_mail_password="${{ secrets.MAIL_PASSWORD }}" @@ -44,3 +44,5 @@ config*.json /.ansible .DS_Store + +/.go-build diff --git a/Jenkinsfile b/Jenkinsfile index e54d972..8633145 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -193,7 +193,7 @@ spec: 'sayauz-web-stage-mail-password' : 'MAIL_PASSWORD' ] def bindings = secretVars.collect { id, varName -> string(credentialsId: id, variable: varName) } - bindings << sshUserPrivateKey(credentialsId: 'sayauz-svc-jenkins', keyFileVariable: 'SSH_KEY_FILE', usernameVariable: 'SSH_USER') + bindings << sshUserPrivateKey(credentialsId: 'sayauz-svc-github', keyFileVariable: 'SSH_KEY_FILE', usernameVariable: 'SSH_USER') withCredentials(bindings) { sh ''' @@ -270,7 +270,7 @@ spec: 'sayauz-web-prod-verification-bing' : 'BING_VERIFICATION' ] def bindings = secretVars.collect { id, varName -> string(credentialsId: id, variable: varName) } - bindings << sshUserPrivateKey(credentialsId: 'sayauz-svc-jenkins', keyFileVariable: 'SSH_KEY_FILE', usernameVariable: 'SSH_USER') + bindings << sshUserPrivateKey(credentialsId: 'sayauz-svc-github', keyFileVariable: 'SSH_KEY_FILE', usernameVariable: 'SSH_USER') withCredentials(bindings) { sh ''' diff --git a/deploy/playbook.yml b/deploy/playbook.yml index c5c71fa..057cc19 100644 --- a/deploy/playbook.yml +++ b/deploy/playbook.yml @@ -26,11 +26,11 @@ community.docker.docker_volume: name: "{{ saya_today_web_name }}-volume" - - name: Deploy saya-today-web Docker Container + - name: Deploy sayauz/web Docker Container community.docker.docker_container: name: "{{ saya_today_web_name }}" hostname: "{{ saya_today_web_hostname }}" - image: "ghcr.io/sayaandy/saya-today-web:{{ saya_today_web_tag }}" + image: "registry.sayag.it/sayauz/web:{{ saya_today_web_tag }}" env: S3_ACCESS_KEY_ID: "{{ saya_today_web_s3_access_key_id }}" S3_SECRET_ACCESS_KEY: "{{ saya_today_web_s3_secret_access_key }}" diff --git a/internal/router/basic-handler.go b/internal/router/basic-handler.go index 68d305c..8398e2b 100644 --- a/internal/router/basic-handler.go +++ b/internal/router/basic-handler.go @@ -42,7 +42,7 @@ func (r *BasicHandler) ContentType() string { return fiber.MIMETextHTMLCharsetUTF8 } -func (r *BasicHandler) RateLimiter() *fiber.Handler { +func (r *BasicHandler) RateLimiter() fiber.Handler { return nil } diff --git a/internal/router/handlers/api-v1-blog-search.go b/internal/router/handlers/api-v1-blog-search.go index b59f09a..322227f 100644 --- a/internal/router/handlers/api-v1-blog-search.go +++ b/internal/router/handlers/api-v1-blog-search.go @@ -44,8 +44,8 @@ func (r *BlogSearchHandler) ToValidateLang() router.LangSetting { return router.InForm } -func (r *BlogSearchHandler) RateLimiter() *fiber.Handler { - return &router.RateLimiterLoose +func (r *BlogSearchHandler) RateLimiter() fiber.Handler { + return router.RateLimiterLoose } func (r *BlogSearchHandler) Render(c *fiber.Ctx, supplements *router.Supplements, lang string, templateMap fiber.Map) (statusCode int, err error) { diff --git a/internal/router/handlers/api-v1-email-send-verification-code.go b/internal/router/handlers/api-v1-email-send-verification-code.go index ea8df4d..190f357 100644 --- a/internal/router/handlers/api-v1-email-send-verification-code.go +++ b/internal/router/handlers/api-v1-email-send-verification-code.go @@ -39,8 +39,8 @@ func (r *SendVerificationCodeHandler) ToValidateLang() router.LangSetting { return router.InReferer } -func (r *SendVerificationCodeHandler) RateLimiter() *fiber.Handler { - return &router.RateLimiterStrict +func (r *SendVerificationCodeHandler) RateLimiter() fiber.Handler { + return router.RateLimiterStrict } func (r *SendVerificationCodeHandler) Render(c *fiber.Ctx, supplements *router.Supplements, lang string, templateMap fiber.Map) (statusCode int, err error) { diff --git a/internal/router/handlers/api-v1-email-verify.go b/internal/router/handlers/api-v1-email-verify.go index 65ad6d9..7649774 100644 --- a/internal/router/handlers/api-v1-email-verify.go +++ b/internal/router/handlers/api-v1-email-verify.go @@ -37,8 +37,8 @@ func (r *VerifyCodeHandler) ToValidateLang() router.LangSetting { return router.InReferer } -func (r *VerifyCodeHandler) RateLimiter() *fiber.Handler { - return &router.RateLimiterStrict +func (r *VerifyCodeHandler) RateLimiter() fiber.Handler { + return router.RateLimiterStrict } func (r *VerifyCodeHandler) Render(c *fiber.Ctx, supplements *router.Supplements, lang string, templateMap fiber.Map) (statusCode int, err error) { diff --git a/internal/router/handlers/api-v1-like-put.go b/internal/router/handlers/api-v1-like-put.go index 8305d2b..c14f76e 100644 --- a/internal/router/handlers/api-v1-like-put.go +++ b/internal/router/handlers/api-v1-like-put.go @@ -37,8 +37,8 @@ func (r *PutLikeHandler) ToValidateLang() router.LangSetting { return router.InReferer } -func (r *PutLikeHandler) RateLimiter() *fiber.Handler { - return &router.RateLimiterMedium +func (r *PutLikeHandler) RateLimiter() fiber.Handler { + return router.RateLimiterMedium } func (r *PutLikeHandler) Render(c *fiber.Ctx, supplements *router.Supplements, lang string, templateMap fiber.Map) (statusCode int, err error) { diff --git a/internal/router/handlers/api-v1-subs-put.go b/internal/router/handlers/api-v1-subs-put.go index 12dc5cf..6d9fd1f 100644 --- a/internal/router/handlers/api-v1-subs-put.go +++ b/internal/router/handlers/api-v1-subs-put.go @@ -35,8 +35,8 @@ func (r *PutSubsHandler) ToValidateLang() router.LangSetting { return router.InReferer } -func (r *PutSubsHandler) RateLimiter() *fiber.Handler { - return &router.RateLimiterMedium +func (r *PutSubsHandler) RateLimiter() fiber.Handler { + return router.RateLimiterMedium } func (r *PutSubsHandler) Render(c *fiber.Ctx, supplements *router.Supplements, lang string, templateMap fiber.Map) (statusCode int, err error) { diff --git a/internal/router/router.go b/internal/router/router.go index a11a934..2869851 100644 --- a/internal/router/router.go +++ b/internal/router/router.go @@ -80,7 +80,7 @@ type Route interface { TemplatesToInject() []string SitemapInfo(supplements *Supplements) []SitemapInfo ContentType() string - RateLimiter() *fiber.Handler + RateLimiter() fiber.Handler Render(c *fiber.Ctx, supplements *Supplements, lang string, templateMap fiber.Map) (statusCode int, err error) AddMeta(c *fiber.Ctx, supplements *Supplements, lang string, templateMap fiber.Map) (meta []MetaField, err error) AddLinkedData(c *fiber.Ctx, supplements *Supplements, lang string, templateMap fiber.Map) (ld map[string]any, err error) @@ -262,7 +262,7 @@ func (r *Router) InitRoutes() (err error) { } if rateLimiter := route.RateLimiter(); rateLimiter != nil { - r.app.Use(match, *rateLimiter) + r.app.Use(match, rateLimiter) } if route.IsTemplated() { |