diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..39cc403e9 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,24 @@ +# Use Ubuntu as base image +FROM ubuntu:20.04 + +# Prevent interactive prompts +ENV DEBIAN_FRONTEND=noninteractive + +# Install Apache +RUN apt-get update && \ + apt-get install -y apache2 && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* + +# Copy website files to Apache document root +COPY . /var/www/html/ + +# Set permissions +RUN chown -R www-data:www-data /var/www/html && \ + chmod -R 755 /var/www/html + +# Expose Apache port +EXPOSE 80 + +# Start Apache in foreground +CMD ["/usr/sbin/apache2ctl", "-D", "FOREGROUND"] diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 000000000..c26b299b9 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,105 @@ +pipeline { + agent any + + environment { + IMAGE_NAME = 'website-app' + PROD_CONTAINER_NAME = 'website-prod' + PROD_PORT = '82' + } + stages { + stage('Checkout') { + steps { + echo "Checking out branch: ${env.BRANCH_NAME}" + checkout scm + } + } + + stage('Validate') { + steps { + script { + echo "Validating repository structure..." + sh ''' + if [ ! -f "index.html" ]; then + echo "Error: index.html not found!" + exit 1 + fi + echo "Validation passed: index.html exists" + ''' + } + } + } + + stage('Build Docker Image') { + steps { + script { + echo "Building Docker image for branch: ${env.BRANCH_NAME}" + def imageTag = "${env.BRANCH_NAME}-${env.BUILD_NUMBER}" + env.IMAGE_TAG = imageTag + sh """ + docker build -t ${env.IMAGE_NAME}:${env.IMAGE_TAG} . + docker tag ${env.IMAGE_NAME}:${env.IMAGE_TAG} ${env.IMAGE_NAME}:${env.BRANCH_NAME}-latest + echo "DOCKER IMAGE BUILT SUCCESSFULLY: ${env.IMAGE_NAME}:${env.IMAGE_TAG}" + """ + } + } + } + + stage('Test Build') { + steps { + script { + echo "Testing Docker image build..." + + def testContainer = "test-container" + def networkName = "jenkins-test-network" + + sh """ + # Create network if it doesn't exist + docker network create ${networkName} 2>/dev/null || true + + # stop and remove any leftover test container + docker rm -f ${testContainer} 2>/dev/null || true + + # Run new test container on port 8081 + docker run -d --name ${testContainer} --network ${networkName} -p 8081:80 ${env.IMAGE_NAME}:${env.IMAGE_TAG} + sleep 20 + + response=\$(docker run --rm --network ${networkName} curlimages/curl -s -o /dev/null -w "%{http_code}" http://${testContainer}:80 || echo "000") + if [ "\$response" != "200" ]; then + echo "Build test failed" + exit 1 + else + echo "Build test passed" + fi + echo "Build test completed successfully" + """ + } + } + } + + stage('Deploy to Production') { + when { + branch 'master' + } + steps { + script { + sh """ + docker stop ${env.PROD_CONTAINER_NAME} 2>/dev/null || true + docker rm ${env.PROD_CONTAINER_NAME} 2>/dev/null || true + docker run -d --name ${env.PROD_CONTAINER_NAME} -p ${env.PROD_PORT}:80 --restart unless-stopped ${env.IMAGE_NAME}:${env.IMAGE_TAG} + """ + echo "Production deployed successfully on port ${env.PROD_PORT}" + } + } + } + } + + post { + always { + sh ''' + docker ps -aq --filter "name=test-container" | xargs -r docker rm -f || true + docker image prune -f || true + echo "Skipping cleanup for debugging" + ''' + } + } +} diff --git a/a.txt b/a.txt new file mode 100644 index 000000000..d863bf454 --- /dev/null +++ b/a.txt @@ -0,0 +1,5 @@ +<<<<<<< HEAD +checking +======= +text feature +>>>>>>> 961e796b7be2c779d3aa290074235e6929d758ae diff --git a/feature.txt b/feature.txt new file mode 100644 index 000000000..17209942c --- /dev/null +++ b/feature.txt @@ -0,0 +1 @@ +checking122 diff --git a/feature2.txt b/feature2.txt new file mode 100644 index 000000000..397ef0bf3 --- /dev/null +++ b/feature2.txt @@ -0,0 +1 @@ +checking8494