chore: Docker setup

main
Lunix-420 2024-10-13 13:16:17 +02:00
parent 71bd26ba69
commit 4d9f603250
2 changed files with 50 additions and 0 deletions

28
Dockerfile 100644
View File

@ -0,0 +1,28 @@
# Use the official Nginx image as the base image
FROM nginx:latest
# Copy custom Nginx configuration for client-side routing
COPY nginx.conf /etc/nginx/conf.d/default.conf
# Clear the default Nginx web content folder
RUN rm -rf /usr/share/nginx/html/*
# Install Git
RUN apt-get update && apt-get install -y git
# Set the working directory to the Nginx web content folder
WORKDIR /usr/share/nginx/html
# Clone the content of the specified GitHub repository
RUN git clone https://gitty.informatik.hs-mannheim.de/Maradona/FrontendDist .
# Expose port 80
EXPOSE 80
# Create a script to perform git pull on startup
RUN echo "#!/bin/sh" > /usr/share/nginx/html/update.sh && \
echo "cd /usr/share/nginx/html && git pull" >> /usr/share/nginx/html/update.sh && \
chmod +x /usr/share/nginx/html/update.sh
# Start Nginx and run the update script
CMD /usr/share/nginx/html/update.sh && nginx -g 'daemon off;'

View File

@ -0,0 +1,22 @@
import subprocess
def build_docker_image(image_name, tag="latest"):
try:
subprocess.run(["docker", "build", "-t", f"{image_name}:{tag}", "."], check=True)
print(f"Successfully built Docker image: {image_name}:{tag}")
except subprocess.CalledProcessError as e:
print(f"Error building Docker image: {e}")
def tag_and_push_image(image_name, tag="latest"):
try:
subprocess.run(["docker", "tag", f"{image_name}:{tag}", f"{image_name}:{tag}"], check=True)
subprocess.run(["docker", "push", f"{image_name}:{tag}"], check=True)
print(f"Successfully tagged and pushed Docker image: {image_name}:{tag}")
except subprocess.CalledProcessError as e:
print(f"Error tagging and pushing Docker image: {e}")
if __name__ == "__main__":
docker_image_name = "teammaradona/frontend"
docker_image_tag = "latest"
build_docker_image(docker_image_name, docker_image_tag)
tag_and_push_image(docker_image_name, docker_image_tag)