Skip to content

Service discovery (#59) #19

Service discovery (#59)

Service discovery (#59) #19

Workflow file for this run

name: services - CD
on:
push:
branches:
- main
paths:
- services/**
env:
REGISTRY: ${{ vars.REGISTRY || 'ghcr.io' }}
TARGET_PLATFORMS: linux/amd64
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
jobs:
changed:
name: Prepare
uses: ./.github/workflows/changes.yml
with:
path: services
dir_names_max_depth: 2
build-and-test:
name: Build-Test (${{ matrix.service-path }})
needs: [changed]
runs-on: ubuntu-latest
if: needs.changed.outputs.any_changed == 'true'
strategy:
matrix:
go-version: ['1.21.x']
service-path: ${{ fromJSON(needs.changed.outputs.matrix) }}
steps:
- uses: actions/checkout@v4
- name: Check for web client
uses: andstor/file-existence-action@v3
id: check_files
with:
files: "services/${{ matrix.service-path }}/web-client/package-lock.json"
- uses: actions/setup-node@v4
if: steps.check_files.outputs.files_exists == 'true'
with:
node-version: 18
cache-dependency-path: services/${{ matrix.service-path }}/web-client/package-lock.json
- name: Install Node dependencies
if: steps.check_files.outputs.files_exists == 'true'
run: |
cd services/${{ matrix.service-path }}/web-client &&
npm i -D @swc/cli @swc/core &&
npm install
- name: Build web-client
if: steps.check_files.outputs.files_exists == 'true'
run: |
cd services/${{ matrix.service-path }}/web-client &&
npm run build
- uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
cache-dependency-path: services/${{ matrix.service-path }}/go.sum
- name: Test
working-directory: services/${{ matrix.service-path }}
run: go test ./...
- name: Build
working-directory: services/${{ matrix.service-path }}
run: go build main.go
docker-image:
name: Docker Image (${{ matrix.service-path }})
needs: [changed]
runs-on: ubuntu-latest
if: needs.changed.outputs.any_changed == 'true'
strategy:
matrix:
service-path: ${{ fromJSON(needs.changed.outputs.matrix) }}
steps:
- uses: actions/checkout@v4
- name: Extract service info
id: info
run: |
echo "domain=$(dirname ${{ matrix.service-path }})" >> $GITHUB_OUTPUT
echo "service=$(basename ${{ matrix.service-path }})" >> $GITHUB_OUTPUT
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ secrets.DOCKER_USERNAME || (env.REGISTRY == 'ghcr.io' && github.actor) }}
password: ${{ secrets.DOCKER_PASSWORD || (env.REGISTRY == 'ghcr.io' && secrets.GITHUB_TOKEN) }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ github.repository }}-${{ steps.info.outputs.domain}}-${{ steps.info.outputs.service }}
tags: |
type=sha
type=edge,branch=main
type=schedule,pattern={{date 'YYYYMMDD-hhmmss' tz='America/Chicago'}}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
file: Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: ${{ env.TARGET_PLATFORMS }}
build-args: |
DOMAIN=${{ steps.info.outputs.domain}}
SERVICE=${{ steps.info.outputs.service}}