feat: Basic working image.
parent
c976e25148
commit
c02c7b2210
|
@ -1,7 +1,7 @@
|
|||
####################
|
||||
# - Stage: Dependencies
|
||||
####################
|
||||
FROM docker.io/rust:1.57-slim-bookworm AS base
|
||||
FROM docker.io/rust:1-slim-bookworm AS base
|
||||
|
||||
ENV CARGO_INSTALL_ROOT /usr/local/
|
||||
ENV CARGO_TARGET_DIR /tmp/target/
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
## Plugins
|
||||
# MDBook Plugins
|
||||
The following plugins for `mdbook` are in use:
|
||||
- `linkcheck`: Checks if links in the book are alive.
|
||||
- **crates.io**: https://crates.io/crates/mdbook-linkcheck
|
||||
|
@ -13,3 +13,9 @@ The following plugins for `mdbook` are in use:
|
|||
- **crates.io**: https://crates.io/crates/mdbook-admonish
|
||||
- `quiz`: Provides interactive quizzes while reading.
|
||||
- **crates.io**: https://crates.io/crates/mdbook-quiz
|
||||
|
||||
# TODO
|
||||
- [ ] Do an `all()` thing for the checks
|
||||
|
||||
# Pre-Commit Hooks
|
||||
https://github.com/compilerla/conventional-pre-commit
|
||||
|
|
108
run.py
108
run.py
|
@ -14,6 +14,7 @@
|
|||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
import os
|
||||
import sys
|
||||
if not all([
|
||||
sys.version_info.major == 3,
|
||||
|
@ -25,15 +26,12 @@ from pathlib import Path
|
|||
import platform
|
||||
import shutil
|
||||
import subprocess
|
||||
import contextlib
|
||||
|
||||
####################
|
||||
# - Constants
|
||||
####################
|
||||
IMAGE_NAME = "docker-mdbook"
|
||||
IMAGE_VERSION = "0.4.34"
|
||||
|
||||
RUST_IMAGE = "docker.io/rust"
|
||||
RUST_TAG = "1-slim-bullseye"
|
||||
SCRIPT_PATH = Path(__file__).resolve().parent
|
||||
|
||||
CMD_DEPENDENCIES = [
|
||||
'podman',
|
||||
|
@ -41,6 +39,16 @@ CMD_DEPENDENCIES = [
|
|||
'pre-commit'
|
||||
]
|
||||
|
||||
IMAGE_NAME = "docker-mdbook"
|
||||
IMAGE_VERSION = ("0", "4", "34")
|
||||
|
||||
REGISTRY_HOST = "git.sofus.io"
|
||||
REGISTRY_USER = "so-rose"
|
||||
REGISTRY_PASSWORD = subprocess.check_output(
|
||||
['pass', 'services/home/git.sofus.io/container-registry-token']
|
||||
).decode('ascii').strip()
|
||||
|
||||
|
||||
####################
|
||||
# - Help Text
|
||||
####################
|
||||
|
@ -112,12 +120,46 @@ def action_help() -> None:
|
|||
####################
|
||||
# - Utilities
|
||||
####################
|
||||
@contextlib.contextmanager
|
||||
def cd_script_dir() -> None:
|
||||
cwd_orig = Path.cwd()
|
||||
|
||||
os.chdir(SCRIPT_PATH)
|
||||
try:
|
||||
yield
|
||||
finally:
|
||||
os.chdir(cwd_orig)
|
||||
|
||||
def get_git_revision_hash(short = True) -> str:
|
||||
commit_id = subprocess.check_output(
|
||||
['git', 'rev-parse', 'HEAD']
|
||||
).decode('ascii').strip()
|
||||
|
||||
return commit_id[:16] if short else commit_id
|
||||
|
||||
def cmd_exists(cmd: str) -> bool:
|
||||
"""Checks if a command exists. Supports Linux, Mac, Windows.
|
||||
"""
|
||||
return shutil.which(cmd) is not None
|
||||
|
||||
|
||||
|
||||
####################
|
||||
# - Checks
|
||||
####################
|
||||
def check_mdbook_version_matches() -> None:
|
||||
with cd_script_dir():
|
||||
with open('Dockerfile', 'r') as f:
|
||||
mdbook_version_lines = [
|
||||
line for line in f.readlines()
|
||||
if line.strip() == f'ARG MDBOOK_VERSION="{".".join(IMAGE_VERSION)}"'
|
||||
]
|
||||
|
||||
if not len(mdbook_version_lines) == 1:
|
||||
print("IMAGE_VERSION doesn't match MDBOOK_VERSION")
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
####################
|
||||
# - Actions
|
||||
####################
|
||||
|
@ -126,14 +168,58 @@ def action_build() -> None:
|
|||
"podman", "build",
|
||||
".",
|
||||
"--target", "base",
|
||||
"--tag", f"{IMAGE_NAME}:{IMAGE_VERSION}",
|
||||
|
||||
# :<commit_id> - Tag Commit ID
|
||||
"--tag",
|
||||
f"{IMAGE_NAME}:{get_git_revision_hash()}",
|
||||
|
||||
])
|
||||
|
||||
|
||||
def action_run() -> None:
|
||||
print(" ".join([
|
||||
"podman", "run", "--rm", "-it",
|
||||
"--volume", "./test:/src",
|
||||
"--workdir", "/src",
|
||||
"--publish", "3000:3000",
|
||||
f"{IMAGE_NAME}:{get_git_revision_hash()}",
|
||||
] + sys.argv[2:],
|
||||
))
|
||||
|
||||
|
||||
def action_publish() -> None:
|
||||
action_build()
|
||||
|
||||
subprocess.run([
|
||||
"podman", "image", "push", "--all-tags",
|
||||
f"git.sofus.io/so-rose/{IMAGE_NAME}",
|
||||
"podman", "login", REGISTRY_HOST,
|
||||
"--username", REGISTRY_USER,
|
||||
"--password", REGISTRY_PASSWORD,
|
||||
])
|
||||
|
||||
# Publish Image @ :<commit_id>
|
||||
subprocess.run([
|
||||
"podman", "image", "push",
|
||||
f"{IMAGE_NAME}:{get_git_revision_hash()}",
|
||||
f"{REGISTRY_HOST}/{REGISTRY_USER}/{IMAGE_NAME}:{get_git_revision_hash()}",
|
||||
])
|
||||
|
||||
# Publish Image @ :M, :M.m, :M.m.p
|
||||
for image_tag in [
|
||||
f"{IMAGE_NAME}:{'.'.join(IMAGE_VERSION)}",
|
||||
f"{IMAGE_NAME}:{'.'.join(IMAGE_VERSION[:2])}",
|
||||
f"{IMAGE_NAME}:{IMAGE_VERSION[0]}",
|
||||
]:
|
||||
subprocess.run([
|
||||
"podman", "tag",
|
||||
f"{IMAGE_NAME}:{get_git_revision_hash()}",
|
||||
image_tag
|
||||
])
|
||||
|
||||
# Publish Image
|
||||
subprocess.run([
|
||||
"podman", "image", "push",
|
||||
image_tag,
|
||||
f"{REGISTRY_HOST}/{REGISTRY_USER}/{image_tag}",
|
||||
])
|
||||
|
||||
|
||||
|
@ -141,14 +227,20 @@ def action_publish() -> None:
|
|||
# - Script
|
||||
####################
|
||||
if __name__ == "__main__":
|
||||
# Check version match w/MDBOOK in Dockerfile
|
||||
check_mdbook_version_matches()
|
||||
|
||||
# Check Available Commands
|
||||
for cmd in CMD_DEPENDENCIES:
|
||||
if not cmd_exists(cmd) :
|
||||
print("One or more dependencies are not installed. Please see --help.")
|
||||
sys.exit(1)
|
||||
|
||||
with cd_script_dir():
|
||||
if len(sys.argv) > 1:
|
||||
{
|
||||
"run": action_run,
|
||||
|
||||
"build": action_build,
|
||||
"publish": action_publish,
|
||||
|
||||
|
|
Loading…
Reference in New Issue