From 95bce9c9e7b0dc5fe82405c5e3614961b6f7b4b0 Mon Sep 17 00:00:00 2001 From: Jens L Date: Fri, 17 Dec 2021 20:49:32 +0100 Subject: [PATCH] outposts: release binary outposts (#1954) * outposts/proxy: always embed static assets, still check local Signed-off-by: Jens Langhammer * ci: add initial ci to build outpost as binary Signed-off-by: Jens Langhammer * ci: fix typo, build web Signed-off-by: Jens Langhammer * ci: upload to release on publish, only run linux on ci Signed-off-by: Jens Langhammer * ci: ensure latest go is used Signed-off-by: Jens Langhammer * ci: split e2e tests into two halves Signed-off-by: Jens Langhammer --- .github/workflows/ci-main.yml | 56 +++++++++++++++++++++++++-- .github/workflows/ci-outpost.yml | 40 ++++++++++++++++++- .github/workflows/release-publish.yml | 49 ++++++++++++++++++++++- Makefile | 7 +++- internal/outpost/proxyv2/handlers.go | 4 +- web/static.go | 7 +++- web/static_outpost.go | 19 +++++++++ 7 files changed, 171 insertions(+), 11 deletions(-) create mode 100644 web/static_outpost.go diff --git a/.github/workflows/ci-main.yml b/.github/workflows/ci-main.yml index 9c39e771f..7d75e8dc5 100644 --- a/.github/workflows/ci-main.yml +++ b/.github/workflows/ci-main.yml @@ -176,7 +176,7 @@ jobs: testspace [integration]unittest.xml --link=codecov - if: ${{ always() }} uses: codecov/codecov-action@v2 - test-e2e: + test-e2e-provider: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 @@ -215,12 +215,59 @@ jobs: npm run build - name: run e2e run: | - pipenv run make test-e2e + pipenv run make test-e2e-provider pipenv run coverage xml - name: run testspace if: ${{ always() }} run: | - testspace [e2e]unittest.xml --link=codecov + testspace [e2e-provider]unittest.xml --link=codecov + - if: ${{ always() }} + uses: codecov/codecov-action@v2 + test-e2e-rest: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-python@v2 + with: + python-version: '3.9' + - uses: actions/setup-node@v2 + with: + node-version: '16' + cache: 'npm' + cache-dependency-path: web/package-lock.json + - uses: testspace-com/setup-testspace@v1 + with: + domain: ${{github.repository_owner}} + - id: cache-pipenv + uses: actions/cache@v2.1.7 + with: + path: ~/.local/share/virtualenvs + key: ${{ runner.os }}-pipenv-v2-${{ hashFiles('**/Pipfile.lock') }} + - name: prepare + env: + INSTALL: ${{ steps.cache-pipenv.outputs.cache-hit }} + run: | + scripts/ci_prepare.sh + docker-compose -f tests/e2e/docker-compose.yml up -d + - id: cache-web + uses: actions/cache@v2.1.7 + with: + path: web/dist + key: ${{ runner.os }}-web-${{ hashFiles('web/package-lock.json', 'web/**') }} + - name: prepare web ui + if: steps.cache-web.outputs.cache-hit != 'true' + run: | + cd web + npm i + npm run build + - name: run e2e + run: | + pipenv run make test-e2e-rest + pipenv run coverage xml + - name: run testspace + if: ${{ always() }} + run: | + testspace [e2e-rest]unittest.xml --link=codecov - if: ${{ always() }} uses: codecov/codecov-action@v2 ci-core-mark: @@ -230,7 +277,8 @@ jobs: - test-migrations-from-stable - test-unittest - test-integration - - test-e2e + - test-e2e-rest + - test-e2e-provider runs-on: ubuntu-latest steps: - run: echo mark diff --git a/.github/workflows/ci-outpost.yml b/.github/workflows/ci-outpost.yml index 7f47039e6..95bdcff78 100644 --- a/.github/workflows/ci-outpost.yml +++ b/.github/workflows/ci-outpost.yml @@ -17,7 +17,7 @@ jobs: - uses: actions/checkout@v2 - uses: actions/setup-go@v2 with: - go-version: '^1.16.3' + go-version: "^1.17" - name: Run linter run: | # Create folder structure for go embeds @@ -80,3 +80,41 @@ jobs: build-args: | GIT_BUILD_HASH=${{ steps.ev.outputs.sha }} platforms: ${{ matrix.arch }} + build-outpost-binary: + timeout-minutes: 120 + needs: + - ci-outpost-mark + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + type: + - proxy + - ldap + goos: [linux] + goarch: [amd64, arm64] + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-go@v2 + with: + go-version: "^1.17" + - uses: actions/setup-node@v2 + with: + node-version: '16' + cache: 'npm' + cache-dependency-path: web/package-lock.json + - name: Build web + run: | + cd web + npm install + npm run build-proxy + - name: Build outpost + run: | + set -x + export GOOS=${{ matrix.goos }} + export GOARCH=${{ matrix.goarch }} + go build -tags=outpost_static_embed -v -o ./authentik-outpost-${{ matrix.type }}_${{ matrix.goos }}_${{ matrix.goarch }} ./cmd/${{ matrix.type }} + - uses: actions/upload-artifact@v2 + with: + name: authentik-outpost-${{ matrix.type }}_${{ matrix.goos }}_${{ matrix.goarch }} + path: ./authentik-outpost-${{ matrix.type }}_${{ matrix.goos }}_${{ matrix.goarch }} diff --git a/.github/workflows/release-publish.yml b/.github/workflows/release-publish.yml index 902e07f73..22bf10b19 100644 --- a/.github/workflows/release-publish.yml +++ b/.github/workflows/release-publish.yml @@ -57,7 +57,7 @@ jobs: - uses: actions/checkout@v2 - uses: actions/setup-go@v2 with: - go-version: "^1.15" + go-version: "^1.17" - name: Set up QEMU uses: docker/setup-qemu-action@v1.2.0 - name: Set up Docker Buildx @@ -93,10 +93,57 @@ jobs: docker pull ghcr.io/goauthentik/${{ matrix.type }}:latest docker tag ghcr.io/goauthentik/${{ matrix.type }}:latest ghcr.io/goauthentik/${{ matrix.type }}:stable docker push ghcr.io/goauthentik/${{ matrix.type }}:stable + build-outpost-binary: + timeout-minutes: 120 + needs: + - ci-outpost-mark + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + type: + - proxy + - ldap + goos: [linux, windows, darwin] + goarch: ["386", amd64, arm64] + exclude: + - goarch: "386" + goos: darwin + - goarch: arm64 + goos: windows + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-go@v2 + with: + go-version: "^1.17" + - uses: actions/setup-node@v2 + with: + node-version: '16' + cache: 'npm' + cache-dependency-path: web/package-lock.json + - name: Build web + run: | + cd web + npm install + npm run build-proxy + - name: Build outpost + run: | + set -x + export GOOS=${{ matrix.goos }} + export GOARCH=${{ matrix.goarch }} + go build -tags=outpost_static_embed -v -o ./authentik-outpost-${{ matrix.type }}_${{ matrix.goos }}_${{ matrix.goarch }} ./cmd/${{ matrix.type }} + - name: Upload binaries to release + uses: svenstaro/upload-release-action@v2 + with: + repo_token: ${{ secrets.GITHUB_TOKEN }} + file: ./authentik-outpost-${{ matrix.type }}_${{ matrix.goos }}_${{ matrix.goarch }} + asset_name: hentik-outpost-${{ matrix.type }}_${{ matrix.goos }}_${{ matrix.goarch }} + tag: ${{ github.ref }} test-release: needs: - build-server - build-outpost + - build-outpost-binary runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 diff --git a/Makefile b/Makefile index 335f10b81..11aec020c 100644 --- a/Makefile +++ b/Makefile @@ -9,8 +9,11 @@ all: lint-fix lint test gen web test-integration: coverage run manage.py test tests/integration -test-e2e: - coverage run manage.py test tests/e2e +test-e2e-provider: + coverage run manage.py test tests/e2e/test_provider* + +test-e2e-rest: + coverage run manage.py test tests/e2e/test_flows* tests/e2e/test_source* test: coverage run manage.py test authentik diff --git a/internal/outpost/proxyv2/handlers.go b/internal/outpost/proxyv2/handlers.go index 2fee7e226..b011131c6 100644 --- a/internal/outpost/proxyv2/handlers.go +++ b/internal/outpost/proxyv2/handlers.go @@ -10,6 +10,7 @@ import ( "github.com/prometheus/client_golang/prometheus" "goauthentik.io/internal/outpost/proxyv2/metrics" "goauthentik.io/internal/utils/web" + staticWeb "goauthentik.io/web" ) func (ps *ProxyServer) HandlePing(rw http.ResponseWriter, r *http.Request) { @@ -28,9 +29,8 @@ func (ps *ProxyServer) HandlePing(rw http.ResponseWriter, r *http.Request) { } func (ps *ProxyServer) HandleStatic(rw http.ResponseWriter, r *http.Request) { - staticFs := http.FileServer(http.Dir("./web/dist/")) before := time.Now() - web.DisableIndex(http.StripPrefix("/akprox/static/dist", staticFs)).ServeHTTP(rw, r) + web.DisableIndex(http.StripPrefix("/akprox/static/dist", staticWeb.StaticHandler)).ServeHTTP(rw, r) after := time.Since(before) metrics.Requests.With(prometheus.Labels{ "outpost_name": ps.akAPI.Outpost.Name, diff --git a/web/static.go b/web/static.go index 77934988b..c8c7d7628 100644 --- a/web/static.go +++ b/web/static.go @@ -1,9 +1,14 @@ package web -import _ "embed" +import ( + _ "embed" + "net/http" +) //go:embed robots.txt var RobotsTxt []byte //go:embed security.txt var SecurityTxt []byte + +var StaticHandler = http.FileServer(http.Dir("./web/dist/")) diff --git a/web/static_outpost.go b/web/static_outpost.go new file mode 100644 index 000000000..8b6e88a4f --- /dev/null +++ b/web/static_outpost.go @@ -0,0 +1,19 @@ +//go:build outpost_static_embed +// +build outpost_static_embed + +package web + +import ( + "embed" + "net/http" +) + +//go:embed dist/* +var StaticDist embed.FS + +//go:embed authentik +var StaticAuthentik embed.FS + +func init() { + StaticHandler = http.FileServer(http.FS(StaticDist)) +}