diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..baeaa00 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,11 @@ +# Stage 1: Build the static site using Hugo +FROM hugomods/hugo:latest AS builder +WORKDIR /src +COPY . . +# Run hugo build to compile markdown into static HTML/CSS/JS in the public/ folder +RUN hugo --minify + +# Stage 2: Serve the compiled static site using Nginx +FROM nginx:alpine +COPY --from=builder /src/public /usr/share/nginx/html +EXPOSE 80 diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..1565e84 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,34 @@ +pipeline { + agent { + node { + label 'dongho' // Runs the deployment on the 'dongho' agent + } + } + + stages { + stage('Checkout') { + steps { + // Pulls the latest changes from the Git repository + checkout scm + + // Initialize and update Git submodules (necessary for themes like themes/paper) + sh 'git submodule update --init --recursive' + } + } + + stage('Build & Deploy') { + steps { + echo 'Building Docker image and starting service...' + // Build the image and recreate container with minimal downtime + sh 'docker compose up -d --build --remove-orphans' + } + } + } + + post { + always { + // Clean up the temporary Jenkins workspace since the files are baked into the image + cleanWs() + } + } +} diff --git a/docker-compose.yml b/docker-compose.yml index 18cd5e0..f5e4b11 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,12 +1,9 @@ +name: blog + services: hugo: - image: hugomods/hugo:latest - command: hugo server --bind 0.0.0.0 --baseURL http://localhost --buildDrafts --buildFuture - volumes: - - .:/src - # ports: - # - "1313:1313" - working_dir: /src + build: . + image: blog-dongho:latest restart: unless-stopped networks: - proxy @@ -22,7 +19,7 @@ services: - traefik.http.routers.blog-secure.rule=Host(`blog.dongho.kim`) - traefik.http.routers.blog-secure.tls=true - traefik.http.routers.blog-secure.tls.certresolver=cloudflare - - traefik.http.services.blog-secure-service.loadbalancer.server.port=1313 + - traefik.http.services.blog-secure-service.loadbalancer.server.port=80 networks: