diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d7ebd9a..ddd1241 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -10,7 +10,7 @@ concurrency: cancel-in-progress: true jobs: - pack-pages: + pack-test-pages: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -21,19 +21,19 @@ jobs: python-version: "3.12" cache: "pip" - run: pip install -r requirements.txt - - id: pack-pages - run: python pack_pages.py + - id: pack-test-pages + run: python scripts/pack_test_pages.py - name: Upload artifact id: upload-artifact uses: actions/upload-artifact@v4 with: name: github-pages - path: ${{ steps.pack-pages.outputs.artifact }} + path: ${{ steps.pack-test-pages.outputs.artifact }} retention-days: 30 - deploy-pages: + deploy-test-pages: runs-on: ubuntu-latest - needs: pack-pages + needs: pack-test-pages permissions: pages: write # to deploy to Pages id-token: write # to verify the deployment originates from an appropriate source @@ -45,9 +45,28 @@ jobs: id: deployment uses: actions/deploy-pages@v4 + build-test-image: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Get Ansible Vault key + run: | + mkdir .ansible + echo "${{ secrets.ANSIBLE_VAULT_KEY }}" > .ansible/vault_key + - uses: actions/setup-python@v4 + with: + python-version: "3.12" + cache: "pip" + - run: pip install -r requirements.txt + - run: python scripts/build_test_image.py ${{ secrets.GITHUB_TOKEN }} + build-python-lib: runs-on: ubuntu-latest - needs: deploy-pages + needs: + - deploy-test-pages + - build-test-image permissions: contents: write steps: @@ -59,4 +78,4 @@ jobs: python-version: "3.12" cache: "pip" - run: pip install -r requirements.txt - - run: python publish_lib.py ${{ secrets.GITHUB_TOKEN }} + - run: python scripts/publish_lib.py ${{ secrets.GITHUB_TOKEN }} diff --git a/.gitignore b/.gitignore index 68bc17f..baf32a7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +.ansible + # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..98ac8c0 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,24 @@ +{ + // For more information, visit: https://go.microsoft.com/fwlink/?LinkId=733558 + "version": "2.0.0", + "tasks": [ + { + "type": "shell", + "command": "ansible-vault encrypt vars/vault.yaml --vault-password-file .ansible/vault_key", + "label": "Encrypt vault", + "problemMatcher": [] + }, + { + "type": "shell", + "command": "ansible-vault decrypt vars/vault.yaml --vault-password-file .ansible/vault_key", + "label": "Decrypt vault", + "problemMatcher": [] + }, + { + "type": "shell", + "command": "ansible-vault view vars/vault.yaml --vault-password-file .ansible/vault_key", + "label": "view vault", + "problemMatcher": [] + } + ] + } \ No newline at end of file diff --git a/TODO.md b/TODO.md index 5b4c1f0..5b79216 100644 --- a/TODO.md +++ b/TODO.md @@ -1,2 +1 @@ -- add NPN publishibg support -- add GitHub pages support \ No newline at end of file +- add NPN publishibg support https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages#publishing-packages-to-the-npm-registry \ No newline at end of file diff --git a/pack_pages.py b/pack_pages.py deleted file mode 100644 index efa2c05..0000000 --- a/pack_pages.py +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env python3 - -from src.github_utils import create_pages_artifact - - -create_pages_artifact(directory="pages") diff --git a/scripts/build_test_image.py b/scripts/build_test_image.py new file mode 100644 index 0000000..3dc2d92 --- /dev/null +++ b/scripts/build_test_image.py @@ -0,0 +1,25 @@ +#!/usr/bin/env python3 + +import sys +from pathlib import Path + +root_directory = Path(__file__).parent +sys.path.append(str(root_directory)) + +from src.ansible_utils import load_vars +from src.docker_utils import build_and_push_docker_img + +root_directory = Path(__file__).parent.parent +data = load_vars(root_directory / '.ansible/vault_key', + root_directory / 'vars/vault.yaml') +docker_username = data['docker_username'] +docker_password = data['docker_password'] + +access_token = sys.argv[1] + +if not access_token: + print("GitHub access token is missing", flush=True, file=sys.stderr) + exit(1) + +build_and_push_docker_img(src="src", tag_prefix="docker-image", + image_name="publish-tools-test", docker_username=docker_username, docker_password=docker_password, github_access_token=access_token) diff --git a/scripts/create_vault_key.py b/scripts/create_vault_key.py new file mode 100644 index 0000000..84ec6c1 --- /dev/null +++ b/scripts/create_vault_key.py @@ -0,0 +1,13 @@ +#!/usr/bin/env python3 + +from pathlib import Path +import sys + +root_directory = Path(__file__).parent.parent +sys.path.append(str(root_directory)) + +from src.ansible_utils import create_vault_key + +root_directory = Path(__file__).parent.parent + +create_vault_key(root_directory / '.ansible/vault_key') \ No newline at end of file diff --git a/scripts/pack_test_pages.py b/scripts/pack_test_pages.py new file mode 100644 index 0000000..ec0ea36 --- /dev/null +++ b/scripts/pack_test_pages.py @@ -0,0 +1,12 @@ +#!/usr/bin/env python3 + +from pathlib import Path +import sys + +root_directory = Path(__file__).parent +sys.path.append(str(root_directory)) + +from src.github_utils import create_pages_artifact + + +create_pages_artifact(directory="test") diff --git a/publish_lib.py b/scripts/publish_lib.py similarity index 94% rename from publish_lib.py rename to scripts/publish_lib.py index 7b85762..39b9716 100644 --- a/publish_lib.py +++ b/scripts/publish_lib.py @@ -5,7 +5,7 @@ from pathlib import Path from setuptools import sandbox -root_directory = Path(__file__).parent +root_directory = Path(__file__).parent.parent sys.path.append(str(root_directory)) diff --git a/src/Dockerfile b/src/Dockerfile new file mode 100644 index 0000000..c3c78df --- /dev/null +++ b/src/Dockerfile @@ -0,0 +1 @@ +FROM alpine \ No newline at end of file diff --git a/src/docker_utils.py b/src/docker_utils.py index 0f56d5a..8b435e3 100644 --- a/src/docker_utils.py +++ b/src/docker_utils.py @@ -6,156 +6,6 @@ from typing import List from .github_utils import create_release from .version_utils import get_version - - -def build_and_push_client_img( - *, - src: Path, - tag_prefix: str, - image_name: str, - docker_username: str, - docker_password: str, - github_access_token: str, - pack_args: List[str] = [], - ignore: List[str] = [], -): - build_and_push_img( - src=src, - tag_prefix=tag_prefix, - image_name=image_name, - pack_args=[ - '--builder', 'paketobuildpacks/builder:base', - '--buildpack', 'paketo-buildpacks/web-servers', - '--buildpack', 'paketo-buildpacks/source-removal', - '--buildpack', 'gcr.io/paketo-buildpacks/health-checker', - '--env', 'BP_NODE_RUN_SCRIPTS=build', - '--env', 'BP_WEB_SERVER=nginx', - '--env', 'BP_WEB_SERVER_ROOT=dist', - '--env', 'BP_WEB_SERVER_ENABLE_PUSH_STATE=true', - '--env', 'BP_NGINX_STUB_STATUS_PORT=8033', - '--env', 'BP_INCLUDE_FILES=nginx.conf:dist/**', - '--env', 'BP_HEALTH_CHECKER_ENABLED=true', - '--env', 'BPE_PORT=80', - '--env', 'THC_PATH=/stub_status', - '--env', 'THC_PORT=8033', - *pack_args, - ], - docker_username=docker_username, - docker_password=docker_password, - github_access_token=github_access_token, - ignore=[ - 'node_modules', - 'dist', - *ignore - ] - ) - - -def build_and_push_server_img( - *, - src: Path, - tag_prefix: str, - image_name: str, - docker_username: str, - docker_password: str, - github_access_token: str, - pack_args: List[str] = [], - ignore: List[str] = [], -): - build_and_push_img( - src=src, - tag_prefix=tag_prefix, - image_name=image_name, - pack_args=[ - '--builder', 'paketobuildpacks/builder:base', - '--buildpack', 'paketo-buildpacks/java', - '--buildpack', 'gcr.io/paketo-buildpacks/health-checker', - '--env', 'BP_JVM_VERSION=17', - '--env', 'BP_HEALTH_CHECKER_ENABLED=true', - '--env', 'BPE_SPRING_PROFILES_ACTIVE=prod', - '--env', 'THC_PATH=/actuator/health/liveness', - '--env', 'THC_PORT=8082', - *pack_args, - ], - docker_username=docker_username, - docker_password=docker_password, - github_access_token=github_access_token, - ignore=[ - 'target', - *ignore - ] - ) - -def build_and_push_python_img( - *, - src: Path, - tag_prefix: str, - image_name: str, - docker_username: str, - docker_password: str, - github_access_token: str, - pack_args: List[str] = [], - ignore: List[str] = [], -): - build_and_push_img( - src=src, - tag_prefix=tag_prefix, - image_name=image_name, - pack_args=[ - '--builder', 'paketobuildpacks/builder:base', - '--buildpack', 'paketo-buildpacks/python', - *pack_args, - ], - docker_username=docker_username, - docker_password=docker_password, - github_access_token=github_access_token, - ignore=[ - 'target', - *ignore - ] - ) - - -def build_and_push_img( - *, - src: Path, - tag_prefix: str, - image_name: str, - docker_username: str, - docker_password: str, - github_access_token: str, - pack_args: List[str] = [], - ignore: List[str] = [], -): - if not github_access_token: - print('GitHub access token is missing', flush=True, file=sys.stderr) - exit(1) - - changed, version = get_version( - src=src, tag_prefix=tag_prefix, ignore=ignore) - - if not changed: - return - - run(['docker', 'login', '--username', docker_username, - '--password-stdin'], input=docker_password.encode(), check=True) - run(['pack', 'build', f'{image_name}:latest', '--path', str(src), '--tag', - f'{image_name}:{version}', '--publish', *pack_args], check=True) - - create_release( - tag_prefix=tag_prefix, - version=version, - access_token=github_access_token, - body=dedent(f''' - [Docker image on DockerHub](https://hub.docker.com/repository/docker/{image_name}) - - ```yaml - image: {image_name}:{version} - ``` - ''') - ) - print( - f'Docker image pushed successfully for {tag_prefix}:{version}', flush=True) def build_and_push_docker_img( *, diff --git a/pages/index.html b/test/index.html similarity index 100% rename from pages/index.html rename to test/index.html diff --git a/vars/vault.yaml b/vars/vault.yaml new file mode 100644 index 0000000..dc9625b --- /dev/null +++ b/vars/vault.yaml @@ -0,0 +1,9 @@ +$ANSIBLE_VAULT;1.1;AES256 +38393661643437653332646263313737663933656331666139626633616663623139363733636633 +6638653635653535633033666265633634306139353939650a383435386361663839326466613061 +63396165643062363837383465653235366232386263663263386465353361303430333634313234 +3562373433323266640a396365666666323839623430396130363565323033393537316536333736 +33623861373038313430303534306639373735306131383164366665353739623532333832656434 +64383836316664633335323132366366663936336564313335663439343263633262393133336533 +30323736343335366637396138386264653063363436633566653630313161633231306333316237 +64613131366666343333