-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Template updates #8
Changes from 8 commits
498674f
e11ceb0
2a0fe17
3a6fdf2
50216b0
96c5b4d
d3320fa
f586922
0192071
f7bf729
b5e2556
c4d4c40
7b5cd3f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,19 +51,40 @@ jobs: | |
- name: Install package | ||
run: poetry install | ||
|
||
- name: Install jq for fingerprinter | ||
run: sudo apt-get -y install jq | ||
|
||
- name: Update env with promotion version that was provided | ||
if: github.event.inputs.version | ||
run: echo "target_version=${{ github.event.inputs.version }}" >> $GITHUB_ENV | ||
|
||
- name: Update env with promotion version if not provided | ||
if: '! env.target_version' | ||
shell: bash | ||
run: | | ||
source ./scripts/globals.sh | ||
target_version=$(get_promotion_version ${{ github.event.inputs.cluster }}) | ||
echo "target_version=${target_version}" >> $GITHUB_ENV | ||
# $1 will be package name, $2 will be current version | ||
set $(poetry version) | ||
|
||
case "${{ github.event.inputs.cluster }}" in | ||
dev) | ||
version="$2" | ||
echo "Would set version to '$version' (from poetry version)" | ||
;; | ||
eval) | ||
# substitute '_' for '-' in APP_NAME | ||
url="https://${1//_/-}.iamdev.s.uw.edu/status" | ||
version=$(curl --silent $url | python -c "import json, sys; print(json.load(sys.stdin)['version'])") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you hate this and want There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm totally good with this |
||
echo "After consulting dev the eval version will be ${version}" | ||
;; | ||
prod) | ||
# substitute '_' for '-' in APP_NAME | ||
url="https://${1//_/-}.iameval.s.uw.edu/status" | ||
version=$(curl --silent $url | python -c "import json, sys; print(json.load(sys.stdin)['version'])") | ||
echo "After consulting eval the prod version will be ${version}" | ||
;; | ||
*) | ||
echo "Invalid cluster! Pick one of dev|eval|prod" | ||
exit 1 | ||
;; | ||
esac | ||
echo "target_version=${version}" >> $GITHUB_ENV | ||
|
||
- name: Auth to Google Cloud | ||
# important! this 'auth' is referenced as `steps.auth` on the next job | ||
|
@@ -80,10 +101,14 @@ jobs: | |
run: |- | ||
echo '${{ steps.auth.outputs.access_token }}' | docker login -u oauth2accesstoken --password-stdin https://us-docker.pkg.dev | ||
|
||
- name: Deploy version ${{ env.target_version }} | ||
- name: Tag version ${{ env.target_version }} for ${{ github.event.inputs.cluster }} | ||
id: deploy | ||
run: | | ||
echo "::notice::Deploying appid version ${{ env.target_version }} to ${{ github.event.inputs.cluster }}" | ||
./scripts/build.sh \ | ||
--deploy ${{ inputs.cluster }} \ | ||
-dversion ${{ env.target_version }} | ||
# timestamp and deploy_tag are not DRY - see also release-on-push-to-main.yaml | ||
timestamp=$(date --utc +%Y.%m.%d.%H.%M.%S) | ||
deploy_tag="deploy-${{ github.event.inputs.cluster }}.${timestamp}.v${{ env.target_version }}" | ||
echo "::notice::Deploying appid version ${{ env.target_version }} to ${{ github.event.inputs.cluster }} as ${deploy_tag}" | ||
# this will create a new tag (deploy_tag) on an existing tag (env.target_version) | ||
docker buildx imagetools create \ | ||
--tag us-docker.pkg.dev/uwit-mci-iam/containers/${template:app_name_hyphen}:${deploy_tag} \ | ||
us-docker.pkg.dev/uwit-mci-iam/containers/${template:app_name_hyphen}:${{ env.target_version }} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ name: Finalize Template | |
on: | ||
workflow_dispatch: | ||
inputs: | ||
app-name: | ||
app_name: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. bugfix - caused the provided app name to always be ignored due to failed lookup |
||
required: false | ||
description: > | ||
This is the name of your app; if left blank, it will match the | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,8 +65,7 @@ jobs: | |
push: true | ||
target: app | ||
tags: | | ||
us-docker.pkg.dev/uwit-mci-iam/containers/${template:app_name}:${{ steps.get-version.outputs.version }} | ||
us-docker.pkg.dev/uwit-mci-iam/containers/${template:app_name}:${{ env.DEPLOYMENT_ID }} | ||
us-docker.pkg.dev/uwit-mci-iam/containers/${template:app_name_hyphen}:${{ steps.get-version.outputs.version }} | ||
us-docker.pkg.dev/uwit-mci-iam/containers/${template:app_name_hyphen}:${{ env.DEPLOYMENT_ID }} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Based on your comment in the body of the PR, didn't you intend to remove It will also need to be removed from the Dockerfile template. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I successfully removed all the DEPLOYMENT_ID stuff |
||
secret-files: | | ||
"gcloud_auth_credentials=${{ steps.auth.outputs.credentials_file_path }}" | ||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,43 +11,40 @@ def get_parser(): | |
"Fills out argument templates, then destroys, saves the new files," | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This source file got "blackened" and thus the changes are pretty noisy. The key here is in (new) lines 41-47 which define an |
||
"and destroys all template files, including this script." | ||
) | ||
parser.add_argument('--app-name', required=True) | ||
parser.add_argument('--maintainer', required=True) | ||
parser.add_argument('--keepalive', required=False, default=False, action='store_true', dest='meta_keepalive') | ||
parser.add_argument("--app-name", required=True) | ||
parser.add_argument("--maintainer", required=True) | ||
parser.add_argument("--keepalive", required=False, default=False, action="store_true", dest="meta_keepalive") | ||
return parser | ||
|
||
|
||
def get_template_files(): | ||
return [ | ||
str(path.joinpath()) for path in list(Path('.').rglob('*.template.*')) | ||
] | ||
return [str(path.joinpath()) for path in list(Path(".").rglob("*.template.*"))] | ||
|
||
|
||
def finalize_template_file(path: str, args: Dict[str, Any]): | ||
with open(path) as f: | ||
template = f.read() | ||
|
||
for key, val in args.items(): | ||
template = template.replace( | ||
f'${{template:{key}}}', str(val) | ||
) | ||
template = template.replace(f"${{template:{key}}}", str(val)) | ||
|
||
new_file_name = path.replace('.template', '') | ||
with open(new_file_name, 'w') as f: | ||
new_file_name = path.replace(".template", "") | ||
with open(new_file_name, "w") as f: | ||
f.write(template) | ||
|
||
logging.info( | ||
f"Generated {new_file_name} from {path}" | ||
) | ||
logging.info(f"Generated {new_file_name} from {path}") | ||
return new_file_name | ||
|
||
|
||
def main(): | ||
args = get_parser().parse_args() | ||
values = { | ||
k: v for k, v in vars(args).items() | ||
if not k.startswith('meta_') | ||
} | ||
values = {k: v for k, v in vars(args).items() if not k.startswith("meta_")} | ||
# add explicit values for only-hypen and only-underscore variants of the app name | ||
# this is important because | ||
# 1) Python package names cannot contain hyphens when importing ('django-utils' illegal; must be 'django_utils') | ||
# 2) subdomains cannot contain underscores and we seed our application subdomains with the application name | ||
values["app_name_hyphen"] = values["app_name"].replace("_", "-") | ||
values["app_name_underscore"] = values["app_name"].replace("-", "_") | ||
logging.basicConfig(level=logging.INFO) | ||
logging.getLogger(__name__).setLevel(logging.INFO) | ||
|
||
|
@@ -58,16 +55,16 @@ def main(): | |
for t in templates: | ||
finalize_template_file(t, values) | ||
if not args.meta_keepalive: | ||
logging.info(f'Deleting template {t}') | ||
logging.info(f"Deleting template {t}") | ||
os.remove(t) | ||
|
||
os.system('poetry update') | ||
os.system("poetry update") | ||
|
||
logging.info('Deleting myself, too. My purpose is fulfilled. Byeeeeeeeeee!') | ||
logging.info("Deleting myself, too. My purpose is fulfilled. Byeeeeeeeeee!") | ||
os.remove(__file__) | ||
|
||
safe_app_name = args.app_name.replace("-", "_") | ||
shutil.move("example_app", safe_app_name) | ||
# this rename tied to Dockerfile.template | ||
shutil.move("example_app", values["app_name_underscore"]) | ||
|
||
|
||
if __name__ == "__main__": | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Flagging that I got a
PermissionError
here on my test innovate_tagging project. I side-stepped it by commenting outpoetry config virtualenvs.create false
on the "Install and configure poetry" task