Skip to content

Commit

Permalink
created initial docker automated workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
wassfila committed Apr 14, 2024
1 parent 90d6832 commit 24445b9
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 39 deletions.
16 changes: 0 additions & 16 deletions Dockerfile

This file was deleted.

1 change: 1 addition & 0 deletions containers/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dockerfiles
21 changes: 21 additions & 0 deletions containers/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
version: "3.8"

services:
#fetches dockerfiles e.g. ./seeds.yaml => ./dockerfiles/astro-big-doc.Dockerfile,...
seeds:
build:
context: ./seeds
volumes:
- ./dockerfiles:/dockerfiles
astro-big-doc:
build:
context: ./dockerfiles
dockerfile: astro-big-doc.Dockerfile
volumes:
- ../content:/astro-big-doc/content
- ../public:/astro-big-doc/public
- ../menu.yaml:/astro-big-doc/menu.yaml
- ../dist:/astro-big-doc/dist
ports:
- "3001:3001"
- "4321:4321"
21 changes: 21 additions & 0 deletions containers/run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import sys
import subprocess
import os

# Path to the directory containing docker-compose.yml
docker_compose_dir = os.path.join(os.path.dirname(__file__))

# Default command if no argument is provided
command = "build"

# Check if an argument is provided and use it as the command
if len(sys.argv) > 1:
command = sys.argv[1]

# Change the working directory
os.chdir(docker_compose_dir)

if(command == "build"):
subprocess.run(["docker-compose", "run", "--rm", "astro-big-doc", "build"])
elif(command == "init"):
subprocess.run(["docker-compose", "run", "--rm", "seeds"])
17 changes: 17 additions & 0 deletions containers/seeds/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Use an official Python runtime as a parent image
FROM python:3.9-slim

# Set the working directory in the container
WORKDIR /app

# Install Python dependencies
RUN pip install pyyaml requests

# Copy the Python script into the container at /app
COPY fetch.py /app/

# Copy the YAML file containing the mappings into the container at /app
COPY seeds.yaml /app/

# Command to run the fetch script
CMD ["python", "fetch.py", "seeds.yaml"]
29 changes: 29 additions & 0 deletions containers/seeds/fetch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import yaml
import requests
import sys

def fetch_and_save_dockerfiles(yaml_input):
# Load the YAML data from string
dockerfile_mappings = yaml.safe_load(yaml_input)

for item in dockerfile_mappings:
for key, url in item.items():
# Fetch the Dockerfile from the URL
response = requests.get(url)
if response.status_code == 200:
# Save the Dockerfile content to a file named <key>.Dockerfile
filename = f"/dockerfiles/{key}.Dockerfile"
with open(filename, 'w') as file:
file.write(response.text)
print(f"Saved {filename}")
else:
print(f"Failed to fetch {url} with status code {response.status_code}")

if __name__ == "__main__":
# Assume the YAML data is passed as a command line argument
if len(sys.argv) > 1:
with open(sys.argv[1], 'r') as file:
yaml_input = file.read()
fetch_and_save_dockerfiles(yaml_input)
else:
print("Please provide a file path to the YAML input as an argument.")
1 change: 1 addition & 0 deletions containers/seeds/seeds.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- astro-big-doc: https://raw.githubusercontent.com/MicroWebStacks/astro-big-doc/main/Dockerfile
12 changes: 0 additions & 12 deletions docker-compose.yaml

This file was deleted.

12 changes: 1 addition & 11 deletions run.cmd
Original file line number Diff line number Diff line change
@@ -1,12 +1,2 @@
@echo off
setlocal

:: Default command if no argument is provided
set COMMAND=build

:: Check if an argument is provided and use it as the command
if not "%~1"=="" set COMMAND=%~1

:: Run the Docker Compose command
docker-compose run --rm astro-doc %COMMAND%
endlocal
python containers\run.py %*

0 comments on commit 24445b9

Please sign in to comment.