-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
* add docker build * incore auth * add example for environment variables * fix bug * fix bug * fix bug * fix docker build * fix typo * only manual trigger * image name * update gh action * update ways to extract app name
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
name: docker | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
dockerfile: | ||
description: 'Select the Dockerfile to use' | ||
required: true | ||
default: 'Dockerfile.dachub_auth' | ||
options: | ||
- Dockerfile.dachub_auth | ||
- Dockerfile.incore_auth | ||
|
||
jobs: | ||
docker: | ||
permissions: | ||
contents: read | ||
packages: write | ||
|
||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
# Extract name from Dockerfile input | ||
- name: Extract Dockerfile name | ||
id: extract_name | ||
run: | | ||
NAME=$(echo "${{ github.event.inputs.dockerfile }}" | cut -d'.' -f2) | ||
echo "IMAGE_NAME=$NAME" >> $GITHUB_ENV | ||
# Create metadata for image | ||
- name: Docker meta | ||
id: meta | ||
uses: docker/metadata-action@v5 | ||
with: | ||
images: | | ||
hub.ncsa.illinois.edu/dachub/${{ env.IMAGE_NAME }} | ||
ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }} | ||
tags: | | ||
type=schedule | ||
type=ref,event=branch | ||
type=ref,event=pr | ||
type=semver,pattern={{version}} | ||
type=semver,pattern={{major}}.{{minor}} | ||
type=semver,pattern={{major}} | ||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@v3 | ||
|
||
- name: Set up Docker Buildx | ||
id: buildx | ||
uses: docker/setup-buildx-action@v3 | ||
|
||
- name: Inspect Builder | ||
run: | | ||
echo "Name: ${{ steps.buildx.outputs.name }}" | ||
echo "Endpoint: ${{ steps.buildx.outputs.endpoint }}" | ||
echo "Status: ${{ steps.buildx.outputs.status }}" | ||
echo "Flags: ${{ steps.buildx.outputs.flags }}" | ||
echo "Platforms: ${{ steps.buildx.outputs.platforms }}" | ||
- name: Login to GitHub Container Registry | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Login to NCSA Hub | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: hub.ncsa.illinois.edu | ||
username: ${{ secrets.NCSA_HUB_USERNAME }} | ||
password: ${{ secrets.NCSA_HUB_PASSWORD }} | ||
|
||
# Build and push | ||
- name: Build and push Docker image | ||
uses: docker/build-push-action@v6 | ||
with: | ||
context: . | ||
file: ${{ github.event.inputs.dockerfile }} | ||
push: true | ||
platforms: linux/amd64 | ||
tags: ${{ steps.meta.outputs.tags }} | ||
labels: ${{ steps.meta.outputs.labels }} | ||
build-args: | | ||
VERSION=${{ steps.meta.outputs.version }} |
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
FROM python:3.7-alpine | ||
|
||
MAINTAINER NCSA | ||
Check warning on line 3 in Dockerfile.dachub_auth GitHub Actions / dockerThe MAINTAINER instruction is deprecated, use a label instead to define an image author
|
||
LABEL PROJECT_REPO_URL = "" \ | ||
Check warning on line 4 in Dockerfile.dachub_auth GitHub Actions / dockerLegacy key/value format with whitespace separator should not be used
|
||
PROJECT_REPO_BROWSER_URL = "" \ | ||
DESCRIPTION = ")" | ||
|
||
WORKDIR /srv | ||
|
||
COPY requirements.txt . | ||
RUN pip3 install -Ur requirements.txt | ||
|
||
COPY dachub_auth dachub_auth | ||
COPY forward_auth dachub_auth/forward_auth | ||
|
||
ENV KEYCLOAK_PUBLIC_KEY="" \ | ||
KEYCLOAK_AUDIENCE="" \ | ||
KEYCLOAK_URL="" | ||
|
||
WORKDIR /srv/dachub_auth | ||
CMD ["gunicorn", "app:app", "--config", "gunicorn.config.py"] |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"PROTECTED_RESOURCES": ["geoserver", "geoserver/web"] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
KEYCLOAK_AUDIENCE= | ||
KEYCLOAK_PUBLIC_KEY= | ||
KEYCLOAK_URL= |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import json | ||
import os | ||
import pytest | ||
from unittest.mock import patch, MagicMock | ||
from flask import Flask | ||
|
||
from app import app # Replace `your_app_module` with the module name of your app | ||
|
||
|
||
@pytest.fixture | ||
def client(): | ||
app.config["TESTING"] = True | ||
with app.test_client() as client: | ||
yield client | ||
|
||
|
||
def test_authorized_request(client): | ||
response = client.get( | ||
"https://localhost:5000/geoserver", # Replace with an actual protected endpoint in your app | ||
headers={"Authorization": "bearer valid_token"} | ||
) | ||
|
||
assert response.status_code == 200 | ||
assert response.headers["X-Auth-UserInfo"] == json.dumps({"preferred_username": "cwang138"}) | ||
assert response.headers["X-Auth-UserGroup"] == json.dumps({"groups": []}) | ||
|
||
|
||
def test_unauthorized_request(client): | ||
response = client.get( | ||
"https://localhost:5000/geoserver", | ||
headers={"Authorization": "Bearer invalid_token"} | ||
) | ||
|
||
assert response.status_code == 401 | ||
assert response.data == b"JWT Error: token is invalid" | ||
|
||
|
||
def test_non_protected_resource(client): | ||
response = client.get("https://localhost:5000/test") | ||
|
||
assert response.status_code == 200 |