diff --git a/.env.develop b/.env.develop new file mode 100644 index 0000000..663d745 --- /dev/null +++ b/.env.develop @@ -0,0 +1,4 @@ +IMAGE_TAG=develop +CONTAINER_NAME=comprofix-develop +HUGO_BASEURL=https://dev.comprofix.com +HOSTNAME=dev.comprofix.com diff --git a/.env.local b/.env.local new file mode 100644 index 0000000..9cb72fb --- /dev/null +++ b/.env.local @@ -0,0 +1,5 @@ +IMAGE_TAG=local +CONTAINER_NAME=comprofix-local +HUGO_BASEURL=http://localhost:8080 +HOSTNAME=localhost +LOCAL_PORT=8080 diff --git a/.env.production b/.env.production new file mode 100644 index 0000000..82a48f6 --- /dev/null +++ b/.env.production @@ -0,0 +1,4 @@ +IMAGE_TAG=latest +CONTAINER_NAME=comprofix +HUGO_BASEURL=https://comprofix.com +HOSTNAME=comprofix.com diff --git a/.gitea/workflows/develop.yml b/.gitea/workflows/develop.yml new file mode 100644 index 0000000..6e0cf54 --- /dev/null +++ b/.gitea/workflows/develop.yml @@ -0,0 +1,59 @@ +name: Build and Deploy Development + +on: + push: + branches: + - develop + +jobs: + build-and-push: + runs-on: ubuntu-latest + env: + DOCKER_REGISTRY: git.comprofix.com + IMAGE_NAME: mmckinnon/comprofix.com + steps: + - uses: actions/checkout@v4 + + - uses: docker/setup-buildx-action@v3 + + - uses: docker/login-action@v3 + with: + registry: ${{ env.DOCKER_REGISTRY }} + username: ${{ secrets.REGISTRY_USERNAME }} + password: ${{ secrets.REGISTRY_TOKEN }} + + - name: Build and push Docker image + uses: docker/build-push-action@v6 + with: + context: . + file: ./Dockerfile + push: true + tags: ${{ env.DOCKER_REGISTRY }}/${{ env.IMAGE_NAME }}:develop + build-args: | + HUGO_BASEURL=https://dev.comprofix.com/ + + deploy: + runs-on: ubuntu-latest + needs: build-and-push + env: + DEPLOY_USER: administrator + DEPLOY_HOST: docker.comprofix.xyz + DEPLOY_PATH: /opt/comprofix + steps: + - uses: actions/checkout@v4 + + - name: Deploy to development server + run: | + mkdir -p ~/.ssh + eval $(ssh-agent -s) + ssh-add <(echo "${{ secrets.SSH_PRIVATE_KEY }}") + + echo "Uploading docker-compose.yml and .env.develop..." + scp docker-compose.yml $DEPLOY_USER@$DEPLOY_HOST:$DEPLOY_PATH + scp .env.develop $DEPLOY_USER@$DEPLOY_HOST:$DEPLOY_PATH/.env + + echo "Deploying development container..." + ssh -o StrictHostKeyChecking=no $DEPLOY_USER@$DEPLOY_HOST " + cd $DEPLOY_PATH + docker compose --env-file .env up -d + " diff --git a/.gitea/workflows/production.yml b/.gitea/workflows/production.yml new file mode 100644 index 0000000..b5c17c2 --- /dev/null +++ b/.gitea/workflows/production.yml @@ -0,0 +1,59 @@ +name: Build and Deploy Production + +on: + push: + tags: + - "v*" + +jobs: + build-and-push: + runs-on: ubuntu-latest + env: + DOCKER_REGISTRY: git.comprofix.com + IMAGE_NAME: mmckinnon/comprofix.com + steps: + - uses: actions/checkout@v4 + + - uses: docker/setup-buildx-action@v3 + + - uses: docker/login-action@v3 + with: + registry: ${{ env.DOCKER_REGISTRY }} + username: ${{ secrets.REGISTRY_USERNAME }} + password: ${{ secrets.REGISTRY_TOKEN }} + + - name: Build and push Docker image + uses: docker/build-push-action@v6 + with: + context: . + file: ./Dockerfile + push: true + tags: ${{ env.DOCKER_REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.ref_name }} + build-args: | + HUGO_BASEURL=https://comprofix.com/ + + deploy: + runs-on: ubuntu-latest + needs: build-and-push + env: + DEPLOY_USER: administrator + DEPLOY_HOST: docker.comprofix.xyz + DEPLOY_PATH: /opt/comprofix + steps: + - uses: actions/checkout@v4 + + - name: Deploy to production server + run: | + mkdir -p ~/.ssh + eval $(ssh-agent -s) + ssh-add <(echo "${{ secrets.SSH_PRIVATE_KEY }}") + + echo "Uploading docker-compose.yml and .env.production..." + scp docker-compose.yml $DEPLOY_USER@$DEPLOY_HOST:$DEPLOY_PATH + scp .env.production $DEPLOY_USER@$DEPLOY_HOST:$DEPLOY_PATH/.env + + echo "Deploying production container..." + ssh -o StrictHostKeyChecking=no $DEPLOY_USER@$DEPLOY_HOST " + cd $DEPLOY_PATH + docker compose --env-file .env up -d + " diff --git a/Dockerfile b/Dockerfile index 6697ba5..4431903 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,22 +1,31 @@ ############### # Build Stage # ############### -FROM hugomods/hugo:exts as builder -# Base URL -# ARG HUGO_BASEURL= -# ENV HUGO_BASEURL=${HUGO_BASEURL} -# Build site +FROM hugomods/hugo:exts AS builder + +# Base URL can be overridden at build time +ARG HUGO_BASEURL +ENV HUGO_BASEURL=${HUGO_BASEURL} + +# Copy source code COPY . /src -RUN hugo --minify --gc -# Set the fallback 404 page if defaultContentLanguageInSubdir is enabled, please replace the `en` with your default language code. + +# Build site with optional baseURL override +RUN if [ -z "$HUGO_BASEURL" ]; then \ + echo "Building site using baseURL from hugo.toml"; \ + hugo --minify --gc --enableGitInfo; \ + else \ + echo "Building site with HUGO_BASEURL=$HUGO_BASEURL"; \ + hugo --minify --gc --enableGitInfo --baseURL "$HUGO_BASEURL"; \ + fi + +# Optional: fallback 404 page for multi-language sites # RUN cp ./public/en/404.html ./public/404.html ############### # Final Stage # ############### FROM hugomods/hugo:nginx -LABEL "Matthew McKinnon"="" +# Copy built static site COPY --from=builder /src/public /site - - diff --git a/docker-compose.local.yml b/docker-compose.local.yml new file mode 100644 index 0000000..d0bd053 --- /dev/null +++ b/docker-compose.local.yml @@ -0,0 +1,9 @@ +version: "3.8" + +services: + comprofix: + container_name: ${CONTAINER_NAME} + image: git.comprofix.com/mmckinnon/comprofix.com:${IMAGE_TAG} + restart: unless-stopped + ports: + - "${LOCAL_PORT}:80" diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..e6c0447 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,19 @@ +version: "3.8" + +services: + comprofix: + container_name: ${CONTAINER_NAME} + image: git.comprofix.com/mmckinnon/comprofix.com:${IMAGE_TAG} + restart: unless-stopped + networks: + - proxy + labels: + - traefik.enable=true + - traefik.http.routers.${CONTAINER_NAME}.rule=Host(`${HOSTNAME}`) + - traefik.http.routers.${CONTAINER_NAME}.entrypoints=https + - traefik.http.routers.${CONTAINER_NAME}.tls=true + - traefik.http.services.${CONTAINER_NAME}.loadbalancer.server.port=80 + +networks: + proxy: + external: true diff --git a/public/404.html b/public/404.html index b04763a..c41e858 100644 --- a/public/404.html +++ b/public/404.html @@ -18,7 +18,7 @@ Comprofix -

404: Page not found

Sorry, we've misplaced that URL or it's pointing to something that doesn't exist.