use cmd line arg for config file rather than env variable

This commit is contained in:
Morgan McMillian 2024-12-24 16:50:30 -08:00
parent fece9465e0
commit a5695069bc
3 changed files with 7 additions and 65 deletions

View file

@ -1,56 +0,0 @@
# This file is a template, and might need editing before it works on your project.
# To contribute improvements to CI/CD templates, please follow the Development guide at:
# https://docs.gitlab.com/ee/development/cicd/templates.html
# This specific template is located at:
# https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/templates/Docker.gitlab-ci.yml
# Build a Docker image with CI/CD and push to the GitLab registry.
# Docker-in-Docker documentation: https://docs.gitlab.com/ee/ci/docker/using_docker_build.html
#
# This template uses one generic job with conditional builds
# for the default branch and all other (MR) branches.
stages:
- build
docker-build:
# Use the official docker image.
image: docker:latest
stage: build
services:
- docker:dind
before_script:
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
# Default branch leaves tag empty (= latest tag)
# All other branches are tagged with the escaped branch name (commit ref slug)
script:
- |
if [[ "$CI_COMMIT_BRANCH" == "$CI_DEFAULT_BRANCH" ]]; then
tag=""
echo "Running on default branch '$CI_DEFAULT_BRANCH': tag = 'latest'"
else
tag=":$CI_COMMIT_REF_SLUG"
echo "Running on branch '$CI_COMMIT_BRANCH': tag = $tag"
fi
- docker build --pull -t "$CI_REGISTRY_IMAGE${tag}" .
- docker push "$CI_REGISTRY_IMAGE${tag}"
# Run this job in a branch where a Dockerfile exists
rules:
- if: $CI_COMMIT_BRANCH
exists:
- Dockerfile
# snap-build-arm64:
# stage: build
# tags:
# - snap-arm64
# script:
# - snapcraft
# - snapcraft upload --release=edge *.snap
#
# snap-build-amd64:
# stage: build
# tags:
# - snap-amd64
# script:
# - snapcraft
# - snapcraft upload --release=edge *.snap

View file

@ -8,6 +8,7 @@ import pnutpy
import textwrap import textwrap
import time import time
import os import os
import argparse
from mautrix.client import ClientAPI from mautrix.client import ClientAPI
from mautrix.types import * from mautrix.types import *
@ -956,9 +957,12 @@ class MLogFilter(logging.Filter):
return True return True
def main(): def main():
configyaml = os.environ.get("CONFIG_FILE") a_parser = argparse.ArgumentParser()
a_parser.add_argument('-c', '--config', dest='configyaml',
default="config.yaml", help="configuration file")
args = a_parser.parse_args()
with open(configyaml, "rb") as config_file: with open(args.configyaml, "rb") as config_file:
config = yaml.load(config_file, Loader=yaml.SafeLoader) config = yaml.load(config_file, Loader=yaml.SafeLoader)
logging.config.dictConfig(config['logging']) logging.config.dictConfig(config['logging'])

View file

@ -458,17 +458,11 @@ def main():
global config global config
global matrix_url global matrix_url
a_parser = argparse.ArgumentParser() a_parser = argparse.ArgumentParser()
a_parser.add_argument(
'-d', action='store_true', dest='debug',
help="debug logging"
)
a_parser.add_argument('-c', '--config', dest='configyaml', a_parser.add_argument('-c', '--config', dest='configyaml',
default="config.yaml", help="configuration file") default="config.yaml", help="configuration file")
args = a_parser.parse_args() args = a_parser.parse_args()
configyaml = os.environ.get("CONFIG_FILE") with open(args.configyaml, "rb") as config_file:
with open(configyaml, "rb") as config_file:
config = yaml.load(config_file, Loader=yaml.SafeLoader) config = yaml.load(config_file, Loader=yaml.SafeLoader)
db.init(config['SERVICE_DB']) db.init(config['SERVICE_DB'])