From 6a9c95c593188f99c1968a9ff944f14797189e66 Mon Sep 17 00:00:00 2001 From: Jens L Date: Sun, 30 May 2021 17:28:58 +0200 Subject: [PATCH] root: generate API Client in dockerfile instead of copying it (#942) * root: generate API Client in dockerfile instead of copying it Signed-off-by: Jens Langhammer * outpost: fix docker build Signed-off-by: Jens Langhammer * root: fix path for docker build Signed-off-by: Jens Langhammer * outpost: set explicit buildContext Signed-off-by: Jens Langhammer --- .github/workflows/release.yml | 15 --------------- .github/workflows/tag.yml | 3 --- Dockerfile | 19 +++++++++++++++---- azure-pipelines.yml | 7 ------- outpost/azure-pipelines.yml | 14 ++------------ outpost/ldap.Dockerfile | 26 ++++++++++++++++++++++---- outpost/proxy.Dockerfile | 26 ++++++++++++++++++++++---- 7 files changed, 61 insertions(+), 49 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 614adc46d..8ac41b82a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -28,9 +28,6 @@ jobs: registry: ghcr.io username: ${{ github.repository_owner }} password: ${{ secrets.GITHUB_TOKEN }} - - name: prepare ts api client - run: | - make gen-web - name: Building Docker Image uses: docker/build-push-action@v2 with: @@ -49,11 +46,6 @@ jobs: - uses: actions/setup-go@v2 with: go-version: "^1.15" - - name: prepare go api client - run: | - make gen-outpost - cd outpost - go build -v ./cmd/proxy/server.go - name: Set up QEMU uses: docker/setup-qemu-action@v1.2.0 - name: Set up Docker Buildx @@ -78,7 +70,6 @@ jobs: beryju/authentik-proxy:latest, ghcr.io/goauthentik/proxy:2021.5.4, ghcr.io/goauthentik/proxy:latest - context: outpost/ file: outpost/proxy.Dockerfile platforms: linux/amd64,linux/arm64 build-ldap: @@ -88,11 +79,6 @@ jobs: - uses: actions/setup-go@v2 with: go-version: "^1.15" - - name: prepare go api client - run: | - make gen-outpost - cd outpost - go build -v ./cmd/ldap/server.go - name: Set up QEMU uses: docker/setup-qemu-action@v1.2.0 - name: Set up Docker Buildx @@ -117,7 +103,6 @@ jobs: beryju/authentik-ldap:latest, ghcr.io/goauthentik/ldap:2021.5.4, ghcr.io/goauthentik/ldap:latest - context: outpost/ file: outpost/ldap.Dockerfile platforms: linux/amd64,linux/arm64 test-release: diff --git a/.github/workflows/tag.yml b/.github/workflows/tag.yml index c9a5966c7..cc2aca624 100644 --- a/.github/workflows/tag.yml +++ b/.github/workflows/tag.yml @@ -11,9 +11,6 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - name: prepare ts api client - run: | - make gen-web - name: Pre-release test run: | sudo apt-get install -y pwgen diff --git a/Dockerfile b/Dockerfile index 6e4bb223a..49aaef08d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,15 +10,27 @@ RUN pip install pipenv && \ pipenv lock -r > requirements.txt && \ pipenv lock -rd > requirements-dev.txt -# Stage 2: Build webui +# Stage 2: Build web API +FROM openapitools/openapi-generator-cli as api-builder + +COPY ./schema.yml /local/schema.yml + +RUN docker-entrypoint.sh generate \ + -i /local/schema.yml \ + -g typescript-fetch \ + -o /local/web/api \ + --additional-properties=typescriptThreePlus=true,supportsES6=true,npmName=authentik-api,npmVersion=1.0.0 + +# Stage 3: Build webui FROM node as npm-builder COPY ./web /static/ +COPY --from=api-builder /local/web/api /static/api ENV NODE_ENV=production RUN cd /static && npm i --production=false && npm run build -# Stage 3: Build go proxy +# Stage 4: Build go proxy FROM golang:1.16.4 AS builder WORKDIR /work @@ -28,7 +40,6 @@ COPY --from=npm-builder /static/security.txt /work/web/security.txt COPY --from=npm-builder /static/dist/ /work/web/dist/ COPY --from=npm-builder /static/authentik/ /work/web/authentik/ -# RUN ls /work/web/static/authentik/ && exit 1 COPY ./cmd /work/cmd COPY ./web/static.go /work/web/static.go COPY ./internal /work/internal @@ -37,7 +48,7 @@ COPY ./go.sum /work/go.sum RUN go build -o /work/authentik ./cmd/server/main.go -# Stage 4: Run +# Stage 5: Run FROM python:3.9-slim-buster WORKDIR / diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 0e439630e..177da1701 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -399,13 +399,6 @@ stages: pool: vmImage: 'ubuntu-latest' steps: - - task: NodeTool@0 - inputs: - versionSpec: '16.x' - displayName: 'Install Node.js' - - task: CmdLine@2 - inputs: - script: make gen-web - task: Bash@3 inputs: targetType: 'inline' diff --git a/outpost/azure-pipelines.yml b/outpost/azure-pipelines.yml index 62f1242b8..8b11dd3cf 100644 --- a/outpost/azure-pipelines.yml +++ b/outpost/azure-pipelines.yml @@ -99,11 +99,6 @@ stages: - task: GoTool@0 inputs: version: '1.16.3' - - task: DownloadPipelineArtifact@2 - inputs: - buildType: 'current' - artifactName: 'go_api_client' - path: "outpost/api/" - task: Bash@3 inputs: targetType: 'inline' @@ -115,7 +110,7 @@ stages: repository: 'authentik/outpost-proxy' command: 'build' Dockerfile: 'outpost/proxy.Dockerfile' - buildContext: 'outpost/' + buildContext: '$(Build.SourcesDirectory)' tags: | gh-$(branchName) gh-$(Build.SourceVersion) @@ -135,11 +130,6 @@ stages: - task: GoTool@0 inputs: version: '1.16.3' - - task: DownloadPipelineArtifact@2 - inputs: - buildType: 'current' - artifactName: 'go_api_client' - path: "outpost/api/" - task: Bash@3 inputs: targetType: 'inline' @@ -151,7 +141,7 @@ stages: repository: 'authentik/outpost-ldap' command: 'build' Dockerfile: 'outpost/ldap.Dockerfile' - buildContext: 'outpost/' + buildContext: '$(Build.SourcesDirectory)' tags: | gh-$(branchName) gh-$(Build.SourceVersion) diff --git a/outpost/ldap.Dockerfile b/outpost/ldap.Dockerfile index a204c15be..4307746f2 100644 --- a/outpost/ldap.Dockerfile +++ b/outpost/ldap.Dockerfile @@ -1,15 +1,33 @@ +# Stage 1: Generate API Client +FROM openapitools/openapi-generator-cli as api-builder + +COPY ./schema.yml /local/schema.yml + +RUN docker-entrypoint.sh generate \ + --git-host goauthentik.io \ + --git-repo-id outpost \ + --git-user-id api \ + -i /local/schema.yml \ + -g go \ + -o /local/outpost/api \ + --additional-properties=packageName=api,enumClassPrefix=true,useOneOfDiscriminatorLookup=true && \ + rm -f /local/outpost/api/go.mod /local/outpost/api/go.sum + +# Stage 2: Build FROM golang:1.16.4 AS builder ARG GIT_BUILD_HASH ENV GIT_BUILD_HASH=$GIT_BUILD_HASH -WORKDIR /work +WORKDIR /go/src/goauthentik.io/outpost -COPY . . +COPY ./outpost . +COPY --from=api-builder /local/outpost/api api -RUN go build -o /work/ldap ./cmd/ldap +RUN go build -o /go/ldap ./cmd/ldap +# Stage 3: Run FROM gcr.io/distroless/base-debian10:debug -COPY --from=builder /work/ldap / +COPY --from=builder /go/ldap / ENTRYPOINT ["/ldap"] diff --git a/outpost/proxy.Dockerfile b/outpost/proxy.Dockerfile index 15861aed0..e45f38bc1 100644 --- a/outpost/proxy.Dockerfile +++ b/outpost/proxy.Dockerfile @@ -1,16 +1,34 @@ +# Stage 1: Generate API Client +FROM openapitools/openapi-generator-cli as api-builder + +COPY ./schema.yml /local/schema.yml + +RUN docker-entrypoint.sh generate \ + --git-host goauthentik.io \ + --git-repo-id outpost \ + --git-user-id api \ + -i /local/schema.yml \ + -g go \ + -o /local/outpost/api \ + --additional-properties=packageName=api,enumClassPrefix=true,useOneOfDiscriminatorLookup=true && \ + rm -f /local/outpost/api/go.mod /local/outpost/api/go.sum + +# Stage 2: Build FROM golang:1.16.4 AS builder ARG GIT_BUILD_HASH ENV GIT_BUILD_HASH=$GIT_BUILD_HASH -WORKDIR /work +WORKDIR /go/src/goauthentik.io/outpost -COPY . . +COPY ./outpost . +COPY --from=api-builder /local/outpost/api api -RUN go build -o /work/proxy ./cmd/proxy +RUN go build -o /go/proxy ./cmd/proxy +# Stage 3: Run FROM gcr.io/distroless/base-debian10:debug -COPY --from=builder /work/proxy / +COPY --from=builder /go/proxy / HEALTHCHECK CMD [ "wget", "--spider", "http://localhost:4180/akprox/ping" ]