From 3162939374a31d303738e9721a18a8f61e953bdd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20S=C3=BC=C3=9F?= Date: Thu, 23 Nov 2023 10:13:39 +0100 Subject: [PATCH] feat: use ko to publish container images --- .github/workflows/ci.yaml | 36 -------------------------------- .github/workflows/deploy.yaml | 39 +++++++++++++++++++++++++++++++++-- backend/Dockerfile | 17 --------------- 3 files changed, 37 insertions(+), 55 deletions(-) delete mode 100644 backend/Dockerfile diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 9e64a5c..86bc447 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -4,10 +4,6 @@ on: - main pull_request: -permissions: - contents: read - packages: write - # This allows a subsequently queued workflow run to interrupt previous runs concurrency: group: '${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}' @@ -24,35 +20,3 @@ jobs: - run: npm ci --force # needed for react-hook-form to play nicely with newer react versions - run: npm test - run: npm run lint - publish-backend: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v4 - - uses: actions/setup-go@v4 - with: - go-version-file: "backend/go.mod" - cache: true - - uses: ko-build/setup-ko@v0.6 - with: - version: v0.15.1 - - name: Login to GitHub Container Registry - uses: docker/login-action@v3 - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - name: Prepare - run: | - echo "BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_ENV - - name: Build and push - working-directory: backend - run: | - export KO_DOCKER_REPO=ghcr.io/grafana/agent-configurator - ko build --sbom=none --bare --platform linux/amd64 -t snapshot \ - --image-label org.opencontainers.image.title=agent-configurator-backend \ - --image-label org.opencontainers.image.description="Backend for the agent-configurator" \ - --image-label org.opencontainers.image.url=${{ github.server_url }}/${{ github.repository }} \ - --image-label org.opencontainers.image.revision=${{ github.sha }} \ - --image-label org.opencontainers.image.version=${{ github.ref_name }} \ - --image-label org.opencontainers.image.created=${{ env.BUILD_DATE }} diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml index 72fa849..8f8375d 100644 --- a/.github/workflows/deploy.yaml +++ b/.github/workflows/deploy.yaml @@ -19,9 +19,44 @@ concurrency: group: "pages" cancel-in-progress: false +permissions: + contents: read + packages: write + jobs: - # Single deploy job since we're just deploying - deploy: + publish-backend: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - uses: actions/setup-go@v4 + with: + go-version-file: "backend/go.mod" + cache: true + - uses: ko-build/setup-ko@v0.6 + with: + version: v0.15.1 + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Prepare + run: | + echo "BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_ENV + - name: Build and push + working-directory: backend + run: | + export KO_DOCKER_REPO=ghcr.io/grafana/agent-configurator-backend + ko build --sbom=none --bare --platform linux/arm64,linux/arm/v7,linux/amd64 -t ${{ github.ref_name } \ + --image-label org.opencontainers.image.title=agent-configurator-backend \ + --image-label org.opencontainers.image.description="Backend for the agent-configurator" \ + --image-label org.opencontainers.image.url=${{ github.server_url }}/${{ github.repository }} \ + --image-label org.opencontainers.image.revision=${{ github.sha }} \ + --image-label org.opencontainers.image.version=${{ github.ref_name }} \ + --image-label org.opencontainers.image.created=${{ env.BUILD_DATE }} + deploy-frontend: environment: name: github-pages url: ${{ steps.deployment.outputs.page_url }} diff --git a/backend/Dockerfile b/backend/Dockerfile deleted file mode 100644 index 9baf0d4..0000000 --- a/backend/Dockerfile +++ /dev/null @@ -1,17 +0,0 @@ -FROM golang:1.21 AS build - -COPY go.mod /src/go.mod -COPY go.sum /src/go.sum - -WORKDIR /src - -RUN go mod download - -COPY . /src - -RUN CGO_ENABLED=0 go build -o agent-configurator-backend . - -FROM ubi8/ubi-micro -COPY --from=build /src/agent-configurator-backend . -EXPOSE 8080 -CMD ./agent-configurator-backend