Skip to content

Commit

Permalink
Added Docker support for Hugo website
Browse files Browse the repository at this point in the history
In this commit, we have added Dockerfile for creating a Docker image of Hugo website. We have updated GitHub actions workflow to build and push the Docker image. Additionally, we have added docker-compose file which will help in running the Docker container locally.
  • Loading branch information
stitts-dev committed May 23, 2024
1 parent e77e18b commit 90af309
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 13 deletions.
21 changes: 8 additions & 13 deletions .github/workflows/deploy-container.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,17 @@ jobs:
deploy:
runs-on: ubuntu-latest
steps:
# checkout to the commit that has been pushed
- uses: actions/checkout@v4.1.4
- name: Check out the repo
uses: actions/checkout@v2

# build and push container image
- name: Build Container
uses: docker/build-push-action@v2
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
context: .
push: true
tags: ${{ secrets.CONTAINER_TAG }}
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}

# deploy to a container registry (e.g., Docker Hub)
- name: Deploy Container
uses: docker/deploy-container@v1
- name: Build and push Docker image
uses: docker/build-push-action@v2
with:
repository: ${{ secrets.CONTAINER_REPO }}
tag: ${{ secrets.CONTAINER_TAG }}
push: true
tags: hugo-site:$(date +%s)
25 changes: 25 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Stage 1
FROM alpine:latest AS build

# Install Go, Hugo, and Git.
RUN apk add --update go hugo git # Added git here

WORKDIR /opt/HugoApp

# Copy Hugo config into the container Workdir.
COPY . .

# Run Hugo in the Workdir to generate HTML.
RUN hugo

# Stage 2
FROM nginx:1.25-alpine

# Set workdir to the NGINX default dir.
WORKDIR /usr/share/nginx/html

# Copy HTML from previous build into the Workdir.
COPY --from=build /opt/HugoApp/public .

# Expose port 80
EXPOSE 80/tcp
10 changes: 10 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: '3.4'

services:
hugo-nginx:
command: ["nginx", "-g", "daemon off;"]
build:
context: .
dockerfile: Dockerfile
ports:
- 80:80

0 comments on commit 90af309

Please sign in to comment.