diff --git a/.github/workflows/publish-docker.yaml b/.github/workflows/publish-docker.yaml new file mode 100644 index 0000000..abb209e --- /dev/null +++ b/.github/workflows/publish-docker.yaml @@ -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 diff --git a/Taskfile.yml b/Taskfile.yml index 54f2758..6f6baf1 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -3,104 +3,107 @@ version: "3" vars: - DOCKER_REGISTRY: "git.aykhans.me/bsky/" + DOCKER_REGISTRY: "git.aykhans.me" tasks: - ftl: - cmds: - - task: fmt - - task: tidy - - task: lint + ftl: + cmds: + - task: fmt + - task: tidy + - 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: - cmd: go run ./cmd/consumer {{.CLI_ARGS}} - dotenv: - - config/app/consumer.env - - config/app/mongodb.env + run-consumer: + cmd: go run ./cmd/consumer {{.CLI_ARGS}} + dotenv: + - config/app/consumer.env + - config/app/mongodb.env - run-feedgen-az: - cmd: go run ./cmd/feedgen/az {{.CLI_ARGS}} - dotenv: - - config/app/feedgen/az.env - - config/app/mongodb.env + run-feedgen-az: + cmd: go run ./cmd/feedgen/az {{.CLI_ARGS}} + dotenv: + - config/app/feedgen/az.env + - config/app/mongodb.env - run-api: - cmd: go run ./cmd/api {{.CLI_ARGS}} - dotenv: - - config/app/api.env - - config/app/mongodb.env + run-api: + cmd: go run ./cmd/api {{.CLI_ARGS}} + dotenv: + - config/app/api.env + - config/app/mongodb.env - run-manager: - cmd: go run cmd/manager/main.go {{.CLI_ARGS}} + run-manager: + cmd: go run cmd/manager/main.go {{.CLI_ARGS}} - docker-publish-all: - desc: Publish docker images for all services - cmds: - - task: docker-publish-api - - task: docker-publish-consumer - - task: docker-publish-feedgen-az - - task: docker-publish-manager + docker-publish-all: + desc: Publish docker images for all services + cmds: + - task: docker-publish-api + - task: docker-publish-consumer + - task: docker-publish-feedgen-az + - task: docker-publish-manager - docker-publish-api: - desc: Publish docker image for api service - vars: - GO_VERSION_FILE: ./cmd/api/version.go - IMAGE_NAME: feedgen-api - VERSION: - sh: grep -o 'const version = "[^"]*"' {{.GO_VERSION_FILE}} | grep -o '"[^"]*"' | tr -d '"' - VERSIONED_IMAGE: "{{.DOCKER_REGISTRY}}{{.IMAGE_NAME}}:{{.VERSION}}" - LATEST_IMAGE: "{{.DOCKER_REGISTRY}}{{.IMAGE_NAME}}:latest" - preconditions: - - test -f {{.GO_VERSION_FILE}} - - sh: '[ -n "{{.VERSION}}" ]' - msg: "Could not extract version from {{.GO_FILE}}" - cmds: - - docker build -t {{.VERSIONED_IMAGE}} -f ./cmd/api/Dockerfile . - - docker tag {{.VERSIONED_IMAGE}} {{.LATEST_IMAGE}} - - docker push {{.VERSIONED_IMAGE}} - - docker push {{.LATEST_IMAGE}} - - echo "Published {{.VERSIONED_IMAGE}} and {{.LATEST_IMAGE}}" + docker-publish-api: + desc: Publish docker image for api service + vars: + GO_VERSION_FILE: ./cmd/api/version.go + IMAGE_NAME: /bsky/feedgen-api + VERSION: + sh: grep -o 'const version = "[^"]*"' {{.GO_VERSION_FILE}} | grep -o '"[^"]*"' | tr -d '"' + VERSIONED_IMAGE: "{{.DOCKER_REGISTRY}}{{.IMAGE_NAME}}:{{.VERSION}}" + LATEST_IMAGE: "{{.DOCKER_REGISTRY}}{{.IMAGE_NAME}}:latest" + preconditions: + - test -f {{.GO_VERSION_FILE}} + - sh: '[ -n "{{.VERSION}}" ]' + msg: "Could not extract version from {{.GO_FILE}}" + cmds: + - docker build -t {{.VERSIONED_IMAGE}} -f ./cmd/api/Dockerfile . + - docker tag {{.VERSIONED_IMAGE}} {{.LATEST_IMAGE}} + - docker push {{.VERSIONED_IMAGE}} + - docker push {{.LATEST_IMAGE}} + - echo "Published {{.VERSIONED_IMAGE}} and {{.LATEST_IMAGE}}" - docker-publish-consumer: - desc: Publish docker image for consumer service - vars: - GO_VERSION_FILE: ./cmd/consumer/version.go - IMAGE_NAME: feedgen-consumer - VERSION: - sh: grep -o 'const version = "[^"]*"' {{.GO_VERSION_FILE}} | grep -o '"[^"]*"' | tr -d '"' - VERSIONED_IMAGE: "{{.DOCKER_REGISTRY}}{{.IMAGE_NAME}}:{{.VERSION}}" - LATEST_IMAGE: "{{.DOCKER_REGISTRY}}{{.IMAGE_NAME}}:latest" - cmds: - - docker build -t {{.VERSIONED_IMAGE}} -f ./cmd/consumer/Dockerfile . - - docker push {{.VERSIONED_IMAGE}} - - docker tag {{.VERSIONED_IMAGE}} {{.LATEST_IMAGE}} - - docker push {{.LATEST_IMAGE}} - - echo "Published {{.VERSIONED_IMAGE}} and {{.LATEST_IMAGE}}" + docker-publish-consumer: + desc: Publish docker image for consumer service + vars: + GO_VERSION_FILE: ./cmd/consumer/version.go + IMAGE_NAME: /bsky/feedgen-consumer + VERSION: + sh: grep -o 'const version = "[^"]*"' {{.GO_VERSION_FILE}} | grep -o '"[^"]*"' | tr -d '"' + VERSIONED_IMAGE: "{{.DOCKER_REGISTRY}}{{.IMAGE_NAME}}:{{.VERSION}}" + LATEST_IMAGE: "{{.DOCKER_REGISTRY}}{{.IMAGE_NAME}}:latest" + cmds: + - docker build -t {{.VERSIONED_IMAGE}} -f ./cmd/consumer/Dockerfile . + - docker push {{.VERSIONED_IMAGE}} + - docker tag {{.VERSIONED_IMAGE}} {{.LATEST_IMAGE}} + - docker push {{.LATEST_IMAGE}} + - echo "Published {{.VERSIONED_IMAGE}} and {{.LATEST_IMAGE}}" - docker-publish-feedgen-az: - desc: Publish docker image for feedgen-az service - vars: - GO_VERSION_FILE: ./cmd/feedgen/az/version.go - IMAGE_NAME: feedgen-generator-az - VERSION: - sh: grep -o 'const version = "[^"]*"' {{.GO_VERSION_FILE}} | grep -o '"[^"]*"' | tr -d '"' - VERSIONED_IMAGE: "{{.DOCKER_REGISTRY}}{{.IMAGE_NAME}}:{{.VERSION}}" - LATEST_IMAGE: "{{.DOCKER_REGISTRY}}{{.IMAGE_NAME}}:latest" - cmds: - - docker build -t {{.VERSIONED_IMAGE}} -f ./cmd/feedgen/az/Dockerfile . - - docker push {{.VERSIONED_IMAGE}} - - docker tag {{.VERSIONED_IMAGE}} {{.LATEST_IMAGE}} - - docker push {{.LATEST_IMAGE}} - - echo "Published {{.VERSIONED_IMAGE}} and {{.LATEST_IMAGE}}" + docker-publish-feedgen-az: + desc: Publish docker image for feedgen-az service + vars: + GO_VERSION_FILE: ./cmd/feedgen/az/version.go + IMAGE_NAME: /bsky/feedgen-generator-az + VERSION: + sh: grep -o 'const version = "[^"]*"' {{.GO_VERSION_FILE}} | grep -o '"[^"]*"' | tr -d '"' + VERSIONED_IMAGE: "{{.DOCKER_REGISTRY}}{{.IMAGE_NAME}}:{{.VERSION}}" + LATEST_IMAGE: "{{.DOCKER_REGISTRY}}{{.IMAGE_NAME}}:latest" + cmds: + - docker build -t {{.VERSIONED_IMAGE}} -f ./cmd/feedgen/az/Dockerfile . + - docker push {{.VERSIONED_IMAGE}} + - docker tag {{.VERSIONED_IMAGE}} {{.LATEST_IMAGE}} + - docker push {{.LATEST_IMAGE}} + - echo "Published {{.VERSIONED_IMAGE}} and {{.LATEST_IMAGE}}" - docker-publish-manager: - desc: Publish docker image for manager service - cmds: - - docker build -t git.aykhans.me/bsky/feedgen-manager:latest -f ./cmd/manager/Dockerfile . - - docker push git.aykhans.me/bsky/feedgen-manager:latest + docker-publish-manager: + desc: Publish docker image for manager service + vars: + GO_VERSION_FILE: ./cmd/manager/version.go + 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