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 <jens.langhammer@beryju.org>

* outpost: fix docker build

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>

* root: fix path for docker build

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>

* outpost: set explicit buildContext

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens L 2021-05-30 17:28:58 +02:00 committed by GitHub
parent 80adafdb48
commit 6a9c95c593
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 61 additions and 49 deletions

View file

@ -28,9 +28,6 @@ jobs:
registry: ghcr.io registry: ghcr.io
username: ${{ github.repository_owner }} username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }} password: ${{ secrets.GITHUB_TOKEN }}
- name: prepare ts api client
run: |
make gen-web
- name: Building Docker Image - name: Building Docker Image
uses: docker/build-push-action@v2 uses: docker/build-push-action@v2
with: with:
@ -49,11 +46,6 @@ jobs:
- uses: actions/setup-go@v2 - uses: actions/setup-go@v2
with: with:
go-version: "^1.15" 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 - name: Set up QEMU
uses: docker/setup-qemu-action@v1.2.0 uses: docker/setup-qemu-action@v1.2.0
- name: Set up Docker Buildx - name: Set up Docker Buildx
@ -78,7 +70,6 @@ jobs:
beryju/authentik-proxy:latest, beryju/authentik-proxy:latest,
ghcr.io/goauthentik/proxy:2021.5.4, ghcr.io/goauthentik/proxy:2021.5.4,
ghcr.io/goauthentik/proxy:latest ghcr.io/goauthentik/proxy:latest
context: outpost/
file: outpost/proxy.Dockerfile file: outpost/proxy.Dockerfile
platforms: linux/amd64,linux/arm64 platforms: linux/amd64,linux/arm64
build-ldap: build-ldap:
@ -88,11 +79,6 @@ jobs:
- uses: actions/setup-go@v2 - uses: actions/setup-go@v2
with: with:
go-version: "^1.15" 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 - name: Set up QEMU
uses: docker/setup-qemu-action@v1.2.0 uses: docker/setup-qemu-action@v1.2.0
- name: Set up Docker Buildx - name: Set up Docker Buildx
@ -117,7 +103,6 @@ jobs:
beryju/authentik-ldap:latest, beryju/authentik-ldap:latest,
ghcr.io/goauthentik/ldap:2021.5.4, ghcr.io/goauthentik/ldap:2021.5.4,
ghcr.io/goauthentik/ldap:latest ghcr.io/goauthentik/ldap:latest
context: outpost/
file: outpost/ldap.Dockerfile file: outpost/ldap.Dockerfile
platforms: linux/amd64,linux/arm64 platforms: linux/amd64,linux/arm64
test-release: test-release:

View file

@ -11,9 +11,6 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- name: prepare ts api client
run: |
make gen-web
- name: Pre-release test - name: Pre-release test
run: | run: |
sudo apt-get install -y pwgen sudo apt-get install -y pwgen

View file

@ -10,15 +10,27 @@ RUN pip install pipenv && \
pipenv lock -r > requirements.txt && \ pipenv lock -r > requirements.txt && \
pipenv lock -rd > requirements-dev.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 FROM node as npm-builder
COPY ./web /static/ COPY ./web /static/
COPY --from=api-builder /local/web/api /static/api
ENV NODE_ENV=production ENV NODE_ENV=production
RUN cd /static && npm i --production=false && npm run build 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 FROM golang:1.16.4 AS builder
WORKDIR /work 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/dist/ /work/web/dist/
COPY --from=npm-builder /static/authentik/ /work/web/authentik/ COPY --from=npm-builder /static/authentik/ /work/web/authentik/
# RUN ls /work/web/static/authentik/ && exit 1
COPY ./cmd /work/cmd COPY ./cmd /work/cmd
COPY ./web/static.go /work/web/static.go COPY ./web/static.go /work/web/static.go
COPY ./internal /work/internal COPY ./internal /work/internal
@ -37,7 +48,7 @@ COPY ./go.sum /work/go.sum
RUN go build -o /work/authentik ./cmd/server/main.go RUN go build -o /work/authentik ./cmd/server/main.go
# Stage 4: Run # Stage 5: Run
FROM python:3.9-slim-buster FROM python:3.9-slim-buster
WORKDIR / WORKDIR /

View file

@ -399,13 +399,6 @@ stages:
pool: pool:
vmImage: 'ubuntu-latest' vmImage: 'ubuntu-latest'
steps: steps:
- task: NodeTool@0
inputs:
versionSpec: '16.x'
displayName: 'Install Node.js'
- task: CmdLine@2
inputs:
script: make gen-web
- task: Bash@3 - task: Bash@3
inputs: inputs:
targetType: 'inline' targetType: 'inline'

View file

@ -99,11 +99,6 @@ stages:
- task: GoTool@0 - task: GoTool@0
inputs: inputs:
version: '1.16.3' version: '1.16.3'
- task: DownloadPipelineArtifact@2
inputs:
buildType: 'current'
artifactName: 'go_api_client'
path: "outpost/api/"
- task: Bash@3 - task: Bash@3
inputs: inputs:
targetType: 'inline' targetType: 'inline'
@ -115,7 +110,7 @@ stages:
repository: 'authentik/outpost-proxy' repository: 'authentik/outpost-proxy'
command: 'build' command: 'build'
Dockerfile: 'outpost/proxy.Dockerfile' Dockerfile: 'outpost/proxy.Dockerfile'
buildContext: 'outpost/' buildContext: '$(Build.SourcesDirectory)'
tags: | tags: |
gh-$(branchName) gh-$(branchName)
gh-$(Build.SourceVersion) gh-$(Build.SourceVersion)
@ -135,11 +130,6 @@ stages:
- task: GoTool@0 - task: GoTool@0
inputs: inputs:
version: '1.16.3' version: '1.16.3'
- task: DownloadPipelineArtifact@2
inputs:
buildType: 'current'
artifactName: 'go_api_client'
path: "outpost/api/"
- task: Bash@3 - task: Bash@3
inputs: inputs:
targetType: 'inline' targetType: 'inline'
@ -151,7 +141,7 @@ stages:
repository: 'authentik/outpost-ldap' repository: 'authentik/outpost-ldap'
command: 'build' command: 'build'
Dockerfile: 'outpost/ldap.Dockerfile' Dockerfile: 'outpost/ldap.Dockerfile'
buildContext: 'outpost/' buildContext: '$(Build.SourcesDirectory)'
tags: | tags: |
gh-$(branchName) gh-$(branchName)
gh-$(Build.SourceVersion) gh-$(Build.SourceVersion)

View file

@ -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 FROM golang:1.16.4 AS builder
ARG GIT_BUILD_HASH ARG GIT_BUILD_HASH
ENV GIT_BUILD_HASH=$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 FROM gcr.io/distroless/base-debian10:debug
COPY --from=builder /work/ldap / COPY --from=builder /go/ldap /
ENTRYPOINT ["/ldap"] ENTRYPOINT ["/ldap"]

View file

@ -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 FROM golang:1.16.4 AS builder
ARG GIT_BUILD_HASH ARG GIT_BUILD_HASH
ENV GIT_BUILD_HASH=$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 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" ] HEALTHCHECK CMD [ "wget", "--spider", "http://localhost:4180/akprox/ping" ]