diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml new file mode 100644 index 0000000..83b1a7c --- /dev/null +++ b/.github/workflows/docker.yaml @@ -0,0 +1,62 @@ +--- +name: Docker Build Action +on: + pull_request: + branches: + - master + release: + types: + - published + push: + branches: + - master + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + build: + name: Docker Build + runs-on: ubuntu-latest + + steps: + - name: Log in to the container registry + uses: docker/login-action@v2 + with: + registry: ${{ env.REGISTRY }} + username: ${{ secrets.DOCKER_REGISTRY_USER }} + password: ${{ secrets.DOCKER_REGISTRY_TOKEN }} + + - name: Checkout + uses: actions/checkout@v3 + + - name: Setup Go + uses: actions/setup-go@v4 + with: + go-version-file: 'go.mod' + cache: false + + - name: Lint + uses: golangci/golangci-lint-action@v3 + with: + args: --build-tags integration -p bugs -p unused --timeout=10m + + - name: Make tag + run: | + [ "${GITHUB_EVENT_NAME}" == 'pull_request' ] && echo "tag=${GITHUB_HEAD_REF##*/}" >> $GITHUB_ENV || true + [ "${GITHUB_EVENT_NAME}" == 'release' ] && echo "tag=${GITHUB_REF##*/}" >> $GITHUB_ENV || true + [ "${GITHUB_EVENT_NAME}" == 'push' ] && echo "tag=latest" >> $GITHUB_ENV || true + + - name: Build and Test + run: | + make test + make client + make server + + - name: Build and push image + uses: docker/build-push-action@v4 + with: + context: . + push: true + tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.tag }} diff --git a/.github/workflows/latest.yaml b/.github/workflows/latest.yaml deleted file mode 100644 index fc10066..0000000 --- a/.github/workflows/latest.yaml +++ /dev/null @@ -1,40 +0,0 @@ -name: Build latest image - -on: - push: - branches: - - master - -jobs: - build: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Docker Login - uses: docker/login-action@v2 - with: - registry: ${{ secrets.DOCKER_REGISTRY }} - username: ${{ secrets.DOCKER_REGISTRY_USER }} - password: ${{ secrets.DOCKER_REGISTRY_TOKEN }} - - - name: Set up Go 1.21 - uses: actions/setup-go@v4 - with: - go-version: "1.21" - id: go - - - name: Lint - uses: golangci/golangci-lint-action@v3 - with: - args: -p bugs -p unused - - - name: Build and push Docker image - run: | - docker build -t ghcr.io/metal-stack/masterdata-api . - docker push ghcr.io/metal-stack/masterdata-api - - - uses: release-drafter/release-drafter@v5 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/pull_request.yaml b/.github/workflows/pull_request.yaml deleted file mode 100644 index 4962b06..0000000 --- a/.github/workflows/pull_request.yaml +++ /dev/null @@ -1,45 +0,0 @@ -name: Build image from pull request - -on: - pull_request: - branches: - - master - -jobs: - build: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Figure out if running fork PR - id: fork - run: '["${{ secrets.DOCKER_REGISTRY_TOKEN }}" == ""] && echo "::set-output name=is_fork_pr::true" || echo "::set-output name=is_fork_pr::false"' - - - name: Docker Login - uses: docker/login-action@v2 - with: - registry: ${{ secrets.DOCKER_REGISTRY }} - username: ${{ secrets.DOCKER_REGISTRY_USER }} - password: ${{ secrets.DOCKER_REGISTRY_TOKEN }} - if: steps.fork.outputs.is_fork_pr == 'false' - - - name: Set up Go 1.21 - uses: actions/setup-go@v4 - with: - go-version: "1.21" - id: go - - - name: Lint - uses: golangci/golangci-lint-action@v3 - with: - args: -p bugs -p unused - - - name: Build Docker image - run: | - docker build -t ghcr.io/metal-stack/masterdata-api:pr-${GITHUB_HEAD_REF##*/} . - - - name: Push Docker image - run: | - docker push ghcr.io/metal-stack/masterdata-api:pr-${GITHUB_HEAD_REF##*/} - if: steps.fork.outputs.is_fork_pr == 'false' diff --git a/.github/workflows/release-drafter.yaml b/.github/workflows/release-drafter.yaml new file mode 100644 index 0000000..da232f3 --- /dev/null +++ b/.github/workflows/release-drafter.yaml @@ -0,0 +1,15 @@ +--- +name: Release Drafter Action + +on: + push: + branches: + - master + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: release-drafter/release-drafter@v5 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml deleted file mode 100644 index 005a4b8..0000000 --- a/.github/workflows/release.yaml +++ /dev/null @@ -1,36 +0,0 @@ -name: Build image from release - -on: - release: - types: - - published - -jobs: - build: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Docker Login - uses: docker/login-action@v2 - with: - registry: ${{ secrets.DOCKER_REGISTRY }} - username: ${{ secrets.DOCKER_REGISTRY_USER }} - password: ${{ secrets.DOCKER_REGISTRY_TOKEN }} - - - name: Set up Go 1.21 - uses: actions/setup-go@v4 - with: - go-version: "1.21" - id: go - - - name: Lint - uses: golangci/golangci-lint-action@v3 - with: - args: -p bugs -p unused - - - name: Build the Docker images - run: | - docker build -t ghcr.io/metal-stack/masterdata-api:${GITHUB_REF##*/} . - docker push ghcr.io/metal-stack/masterdata-api:${GITHUB_REF##*/} diff --git a/Dockerfile b/Dockerfile index 69a58b1..75e45d6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,10 +6,8 @@ RUN apk -U add curl \ ${GRPC_HEALTH_PROBE_URL}/${GRPC_HEALTH_PROBE_VERSION}/grpc_health_probe-linux-amd64 \ && chmod +x /bin/grpc_health_probe -FROM ghcr.io/metal-stack/builder:latest as builder - FROM alpine:3.18 RUN apk -U add ca-certificates -COPY --from=builder /work/bin/server /masterdata-api COPY --from=health-downloader /bin/grpc_health_probe /bin/grpc_health_probe +COPY bin/server /masterdata-api CMD ["/masterdata-api"] diff --git a/Dockerfile.dev b/Dockerfile.dev deleted file mode 100644 index 75e45d6..0000000 --- a/Dockerfile.dev +++ /dev/null @@ -1,13 +0,0 @@ -FROM alpine:3.18 as health-downloader -ENV GRPC_HEALTH_PROBE_VERSION=v0.4.19 \ - GRPC_HEALTH_PROBE_URL=https://github.com/grpc-ecosystem/grpc-health-probe/releases/download -RUN apk -U add curl \ - && curl -fLso /bin/grpc_health_probe \ - ${GRPC_HEALTH_PROBE_URL}/${GRPC_HEALTH_PROBE_VERSION}/grpc_health_probe-linux-amd64 \ - && chmod +x /bin/grpc_health_probe - -FROM alpine:3.18 -RUN apk -U add ca-certificates -COPY --from=health-downloader /bin/grpc_health_probe /bin/grpc_health_probe -COPY bin/server /masterdata-api -CMD ["/masterdata-api"] diff --git a/Makefile b/Makefile index e3fd17b..d807f91 100644 --- a/Makefile +++ b/Makefile @@ -4,8 +4,8 @@ DOCKER_TAG := $(or ${GITHUB_TAG_NAME}, latest) SHA := $(shell git rev-parse --short=8 HEAD) GITVERSION := $(shell git describe --long --all) -BUILDDATE := $(shell date -Iseconds) -VERSION := $(or ${VERSION},devel) +BUILDDATE := $(shell date --rfc-3339=seconds) +VERSION := $(or ${VERSION},$(shell git describe --tags --exact-match 2> /dev/null || git symbolic-ref -q --short HEAD || git rev-parse --short HEAD)) .PHONY: all all: generate test server client