Skip to content

Commit

Permalink
Merge pull request #48 from McCloudS/launcher
Browse files Browse the repository at this point in the history
Launcher
  • Loading branch information
McCloudS authored Feb 11, 2024
2 parents 202a4d1 + 7a8e145 commit f1760fb
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 57 deletions.
58 changes: 3 additions & 55 deletions .github/workflows/github-actions-builddockerfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Build_Subgen_Dockerfile
on:
push:
branches:
- 'main'
- 'launcher'
paths-ignore:
- '**.md'
- '**.yml'
Expand All @@ -13,67 +13,15 @@ jobs:
docker:
runs-on: ubuntu-latest
steps:
-
name: Check disk space
run: df . -h
-
name: Free disk space
run: |
sudo docker rmi $(docker image ls -aq) >/dev/null 2>&1 || true
sudo rm -rf \
/usr/share/dotnet /usr/local/lib/android /opt/ghc \
/usr/local/share/powershell /usr/share/swift /usr/local/.ghcup \
/usr/lib/jvm || true
sudo rm -rf /usr/share/dotnet
sudo rm -rf /opt/ghc
sudo rm -rf "/usr/local/share/boost"
sudo rm -rf "$AGENT_TOOLSDIRECTORY"
echo "some directories deleted"
sudo apt install aptitude -y >/dev/null 2>&1
sudo aptitude purge aria2 ansible azure-cli shellcheck rpm xorriso zsync \
esl-erlang firefox gfortran-8 gfortran-9 google-chrome-stable \
google-cloud-sdk imagemagick \
libmagickcore-dev libmagickwand-dev libmagic-dev ant ant-optional kubectl \
mercurial apt-transport-https mono-complete libmysqlclient \
unixodbc-dev yarn chrpath libssl-dev libxft-dev \
libfreetype6 libfreetype6-dev libfontconfig1 libfontconfig1-dev \
snmp pollinate libpq-dev postgresql-client powershell ruby-full \
sphinxsearch subversion mongodb-org azure-cli microsoft-edge-stable \
-y -f >/dev/null 2>&1
sudo aptitude purge google-cloud-sdk -f -y >/dev/null 2>&1
sudo aptitude purge microsoft-edge-stable -f -y >/dev/null 2>&1 || true
sudo apt purge microsoft-edge-stable -f -y >/dev/null 2>&1 || true
sudo aptitude purge '~n ^mysql' -f -y >/dev/null 2>&1
sudo aptitude purge '~n ^php' -f -y >/dev/null 2>&1
sudo aptitude purge '~n ^dotnet' -f -y >/dev/null 2>&1
sudo apt-get autoremove -y >/dev/null 2>&1
sudo apt-get autoclean -y >/dev/null 2>&1
echo "some packages purged"
-
name: Check disk space
run: |
df . -h
-
name: Login to Docker Hub
uses: docker/[email protected]
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
-
name: Log in to the Github Container registry
uses: docker/[email protected]
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/checkout@v3
- uses: docker/setup-buildx-action@v3
-
name: Build
name: Build and push
uses: docker/build-push-action@v5
with:
context: .
cache-from: type=gha
cache-to: type=gha,mode=max
push: true
tags: mccloud/subgen:latest
tags: mccloud/subgen:launcher
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ RUN apt-get update \
accelerate \
optimum

ADD https://raw.githubusercontent.com/McCloudS/subgen/main/subgen/subgen.py /subgen/subgen.py
ADD https://raw.githubusercontent.com/McCloudS/subgen/main/launcher.py /subgen/launcher.py

CMD [ "python3", "-u", "./subgen.py" ]
CMD [ "bash", "-c", "python3 -u launcher.py && python3 -u subgen.py" ]

EXPOSE 8090
37 changes: 37 additions & 0 deletions launcher.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import os
import requests

def convert_to_bool(in_bool):
if isinstance(in_bool, bool):
return in_bool
else:
value = str(in_bool).lower()
return value not in ('false', 'off', '0', 0)

def download_from_github(url, output_file):
response = requests.get(url)
if response.status_code == 200:
with open(output_file, 'wb') as f:
f.write(response.content)
print(f"File downloaded successfully to {output_file}")
else:
print(f"Failed to download file from {url}")

def main():
github_url = "https://raw.githubusercontent.com/McCloudS/subgen/main/subgen/subgen.py"
output_file = "subgen.py"

# Check if the environment variable is set
github_download_enabled = convert_to_bool(os.getenv("UPDATE", False))

if not os.path.exists(output_file):
print(f"File {output_file} does not exist. Downloading from GitHub...")
download_from_github(github_url, output_file)
elif github_download_enabled:
print(f"File exists, but UPDATE is set to True. Downloading {output_file} from GitHub...")
download_from_github(github_url, output_file)
else:
print("Environment variable UPDATE is not set or set to False, skipping download.")

if __name__ == "__main__":
main()

0 comments on commit f1760fb

Please sign in to comment.