Skip to content

Commit

Permalink
Change entrypoint to use python script instead of bash
Browse files Browse the repository at this point in the history
  • Loading branch information
erickgnavar committed May 21, 2024
1 parent 8e4a253 commit ebf3b48
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 34 deletions.
8 changes: 3 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
FROM alpine:3.19
FROM python:3.12-alpine

RUN apk --update add curl bash
COPY main.py /main.py

COPY entrypoint.sh /entrypoint.sh

ENTRYPOINT ["/entrypoint.sh"]
ENTRYPOINT ["/main.py"]
29 changes: 0 additions & 29 deletions entrypoint.sh

This file was deleted.

42 changes: 42 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env python

import os
import sys
from urllib import parse
from urllib.error import HTTPError
from urllib.parse import urlparse
from urllib.request import Request, urlopen

PROJECT = os.environ.get("INPUT_PROJECT")
ENVIRONMENT = os.environ.get("INPUT_ENVIRONMENT")
IMAGE_VERSION = os.environ.get("INPUT_IMAGE_VERSION")
GITHUB_USERNAME = os.environ.get("GITHUB_ACTOR")
URL = os.environ.get("INPUT_URL")


def main():
uri = urlparse(URL)
token = uri.username
url = f"{uri.scheme}://{uri.hostname}:{uri.port}{uri.path}"

payload = {
"environment_type": ENVIRONMENT,
"project_name": PROJECT,
"image_version": IMAGE_VERSION,
"github_username": GITHUB_USERNAME,
}
data = parse.urlencode(payload).encode()
request = Request(url, headers={"X-Api-Key": str(token)}, data=data)
try:
with urlopen(request) as response:
if response.status == 201:
sys.stdout.write(
f"Deployment created with uid: {response.read().decode()}\n"
)
except HTTPError as error:
sys.stderr.write(f"HTTP Error: {error.reason} {error.read().decode()}")
sys.exit(1)


if __name__ == "__main__":
main()

0 comments on commit ebf3b48

Please sign in to comment.