update CI/CD

This commit is contained in:
2025-10-25 15:54:35 +04:00
parent 76d4dbd105
commit 2b71a6d0e7
2 changed files with 189 additions and 87 deletions

99
.github/workflows/publish-docker.yaml vendored Normal file
View File

@@ -0,0 +1,99 @@
name: Publish Docker Images
on:
push:
branches:
- main
paths:
- 'cmd/*/version.go'
- 'cmd/feedgen/*/version.go'
jobs:
detect-changes:
runs-on: ubuntu-latest
outputs:
api: ${{ steps.filter.outputs.api }}
consumer: ${{ steps.filter.outputs.consumer }}
feedgen-az: ${{ steps.filter.outputs.feedgen-az }}
steps:
- uses: actions/checkout@v4
- uses: dorny/paths-filter@v3
id: filter
with:
filters: |
api:
- 'cmd/api/version.go'
consumer:
- 'cmd/consumer/version.go'
feedgen-az:
- 'cmd/feedgen/az/version.go'
publish-api:
needs: detect-changes
if: needs.detect-changes.outputs.api == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Registry
uses: docker/login-action@v3
with:
registry: git.aykhans.me
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Install Task
uses: arduino/setup-task@v2
- name: Build and publish API
run: task docker-publish-api
publish-consumer:
needs: detect-changes
if: needs.detect-changes.outputs.consumer == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Registry
uses: docker/login-action@v3
with:
registry: git.aykhans.me
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Install Task
uses: arduino/setup-task@v2
- name: Build and publish Consumer
run: task docker-publish-consumer
publish-feedgen-az:
needs: detect-changes
if: needs.detect-changes.outputs.feedgen-az == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Registry
uses: docker/login-action@v3
with:
registry: git.aykhans.me
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Install Task
uses: arduino/setup-task@v2
- name: Build and publish Feedgen AZ
run: task docker-publish-feedgen-az

View File

@@ -3,104 +3,107 @@
version: "3" version: "3"
vars: vars:
DOCKER_REGISTRY: "git.aykhans.me/bsky/" DOCKER_REGISTRY: "git.aykhans.me"
tasks: tasks:
ftl: ftl:
cmds: cmds:
- task: fmt - task: fmt
- task: tidy - task: tidy
- task: lint - task: lint
fmt: gofmt -w -d . fmt: gofmt -w -d .
tidy: go mod tidy tidy: go mod tidy
lint: golangci-lint run lint: golangci-lint run
run-consumer: run-consumer:
cmd: go run ./cmd/consumer {{.CLI_ARGS}} cmd: go run ./cmd/consumer {{.CLI_ARGS}}
dotenv: dotenv:
- config/app/consumer.env - config/app/consumer.env
- config/app/mongodb.env - config/app/mongodb.env
run-feedgen-az: run-feedgen-az:
cmd: go run ./cmd/feedgen/az {{.CLI_ARGS}} cmd: go run ./cmd/feedgen/az {{.CLI_ARGS}}
dotenv: dotenv:
- config/app/feedgen/az.env - config/app/feedgen/az.env
- config/app/mongodb.env - config/app/mongodb.env
run-api: run-api:
cmd: go run ./cmd/api {{.CLI_ARGS}} cmd: go run ./cmd/api {{.CLI_ARGS}}
dotenv: dotenv:
- config/app/api.env - config/app/api.env
- config/app/mongodb.env - config/app/mongodb.env
run-manager: run-manager:
cmd: go run cmd/manager/main.go {{.CLI_ARGS}} cmd: go run cmd/manager/main.go {{.CLI_ARGS}}
docker-publish-all: docker-publish-all:
desc: Publish docker images for all services desc: Publish docker images for all services
cmds: cmds:
- task: docker-publish-api - task: docker-publish-api
- task: docker-publish-consumer - task: docker-publish-consumer
- task: docker-publish-feedgen-az - task: docker-publish-feedgen-az
- task: docker-publish-manager - task: docker-publish-manager
docker-publish-api: docker-publish-api:
desc: Publish docker image for api service desc: Publish docker image for api service
vars: vars:
GO_VERSION_FILE: ./cmd/api/version.go GO_VERSION_FILE: ./cmd/api/version.go
IMAGE_NAME: feedgen-api IMAGE_NAME: /bsky/feedgen-api
VERSION: VERSION:
sh: grep -o 'const version = "[^"]*"' {{.GO_VERSION_FILE}} | grep -o '"[^"]*"' | tr -d '"' sh: grep -o 'const version = "[^"]*"' {{.GO_VERSION_FILE}} | grep -o '"[^"]*"' | tr -d '"'
VERSIONED_IMAGE: "{{.DOCKER_REGISTRY}}{{.IMAGE_NAME}}:{{.VERSION}}" VERSIONED_IMAGE: "{{.DOCKER_REGISTRY}}{{.IMAGE_NAME}}:{{.VERSION}}"
LATEST_IMAGE: "{{.DOCKER_REGISTRY}}{{.IMAGE_NAME}}:latest" LATEST_IMAGE: "{{.DOCKER_REGISTRY}}{{.IMAGE_NAME}}:latest"
preconditions: preconditions:
- test -f {{.GO_VERSION_FILE}} - test -f {{.GO_VERSION_FILE}}
- sh: '[ -n "{{.VERSION}}" ]' - sh: '[ -n "{{.VERSION}}" ]'
msg: "Could not extract version from {{.GO_FILE}}" msg: "Could not extract version from {{.GO_FILE}}"
cmds: cmds:
- docker build -t {{.VERSIONED_IMAGE}} -f ./cmd/api/Dockerfile . - docker build -t {{.VERSIONED_IMAGE}} -f ./cmd/api/Dockerfile .
- docker tag {{.VERSIONED_IMAGE}} {{.LATEST_IMAGE}} - docker tag {{.VERSIONED_IMAGE}} {{.LATEST_IMAGE}}
- docker push {{.VERSIONED_IMAGE}} - docker push {{.VERSIONED_IMAGE}}
- docker push {{.LATEST_IMAGE}} - docker push {{.LATEST_IMAGE}}
- echo "Published {{.VERSIONED_IMAGE}} and {{.LATEST_IMAGE}}" - echo "Published {{.VERSIONED_IMAGE}} and {{.LATEST_IMAGE}}"
docker-publish-consumer: docker-publish-consumer:
desc: Publish docker image for consumer service desc: Publish docker image for consumer service
vars: vars:
GO_VERSION_FILE: ./cmd/consumer/version.go GO_VERSION_FILE: ./cmd/consumer/version.go
IMAGE_NAME: feedgen-consumer IMAGE_NAME: /bsky/feedgen-consumer
VERSION: VERSION:
sh: grep -o 'const version = "[^"]*"' {{.GO_VERSION_FILE}} | grep -o '"[^"]*"' | tr -d '"' sh: grep -o 'const version = "[^"]*"' {{.GO_VERSION_FILE}} | grep -o '"[^"]*"' | tr -d '"'
VERSIONED_IMAGE: "{{.DOCKER_REGISTRY}}{{.IMAGE_NAME}}:{{.VERSION}}" VERSIONED_IMAGE: "{{.DOCKER_REGISTRY}}{{.IMAGE_NAME}}:{{.VERSION}}"
LATEST_IMAGE: "{{.DOCKER_REGISTRY}}{{.IMAGE_NAME}}:latest" LATEST_IMAGE: "{{.DOCKER_REGISTRY}}{{.IMAGE_NAME}}:latest"
cmds: cmds:
- docker build -t {{.VERSIONED_IMAGE}} -f ./cmd/consumer/Dockerfile . - docker build -t {{.VERSIONED_IMAGE}} -f ./cmd/consumer/Dockerfile .
- docker push {{.VERSIONED_IMAGE}} - docker push {{.VERSIONED_IMAGE}}
- docker tag {{.VERSIONED_IMAGE}} {{.LATEST_IMAGE}} - docker tag {{.VERSIONED_IMAGE}} {{.LATEST_IMAGE}}
- docker push {{.LATEST_IMAGE}} - docker push {{.LATEST_IMAGE}}
- echo "Published {{.VERSIONED_IMAGE}} and {{.LATEST_IMAGE}}" - echo "Published {{.VERSIONED_IMAGE}} and {{.LATEST_IMAGE}}"
docker-publish-feedgen-az: docker-publish-feedgen-az:
desc: Publish docker image for feedgen-az service desc: Publish docker image for feedgen-az service
vars: vars:
GO_VERSION_FILE: ./cmd/feedgen/az/version.go GO_VERSION_FILE: ./cmd/feedgen/az/version.go
IMAGE_NAME: feedgen-generator-az IMAGE_NAME: /bsky/feedgen-generator-az
VERSION: VERSION:
sh: grep -o 'const version = "[^"]*"' {{.GO_VERSION_FILE}} | grep -o '"[^"]*"' | tr -d '"' sh: grep -o 'const version = "[^"]*"' {{.GO_VERSION_FILE}} | grep -o '"[^"]*"' | tr -d '"'
VERSIONED_IMAGE: "{{.DOCKER_REGISTRY}}{{.IMAGE_NAME}}:{{.VERSION}}" VERSIONED_IMAGE: "{{.DOCKER_REGISTRY}}{{.IMAGE_NAME}}:{{.VERSION}}"
LATEST_IMAGE: "{{.DOCKER_REGISTRY}}{{.IMAGE_NAME}}:latest" LATEST_IMAGE: "{{.DOCKER_REGISTRY}}{{.IMAGE_NAME}}:latest"
cmds: cmds:
- docker build -t {{.VERSIONED_IMAGE}} -f ./cmd/feedgen/az/Dockerfile . - docker build -t {{.VERSIONED_IMAGE}} -f ./cmd/feedgen/az/Dockerfile .
- docker push {{.VERSIONED_IMAGE}} - docker push {{.VERSIONED_IMAGE}}
- docker tag {{.VERSIONED_IMAGE}} {{.LATEST_IMAGE}} - docker tag {{.VERSIONED_IMAGE}} {{.LATEST_IMAGE}}
- docker push {{.LATEST_IMAGE}} - docker push {{.LATEST_IMAGE}}
- echo "Published {{.VERSIONED_IMAGE}} and {{.LATEST_IMAGE}}" - echo "Published {{.VERSIONED_IMAGE}} and {{.LATEST_IMAGE}}"
docker-publish-manager: docker-publish-manager:
desc: Publish docker image for manager service desc: Publish docker image for manager service
cmds: vars:
- docker build -t git.aykhans.me/bsky/feedgen-manager:latest -f ./cmd/manager/Dockerfile . GO_VERSION_FILE: ./cmd/manager/version.go
- docker push git.aykhans.me/bsky/feedgen-manager:latest IMAGE_NAME: /bsky/feedgen-manager
cmds:
- docker build -t {{.DOCKER_REGISTRY}}{{.IMAGE_NAME}}:latest -f ./cmd/manager/Dockerfile .
- docker push {{.DOCKER_REGISTRY}}{{.IMAGE_NAME}}:latest