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 22, 2024
1 parent 8e4a253 commit ac93e14
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 40 deletions.
14 changes: 8 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
---
name: CI

on: push

jobs:
run-linters:
runs-on: ubuntu-latest
container: python:3.12-alpine
steps:
- name: Check out the repo
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Install shellcheck
run: sudo apt update && sudo apt install shellcheck --yes

- name: Run shellcheck
run: shellcheck entrypoint.sh
- name: Run linter and formatter with ruff
run: |
pip install ruff
ruff format --check .
ruff check --output-format github .
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.

43 changes: 43 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/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
# remove token because it will be send in headers
url = uri.geturl().replace(f"{token}@", "")

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 ac93e14

Please sign in to comment.