From c9b08b210b7e64a08ffdb4855384f9f631283268 Mon Sep 17 00:00:00 2001 From: qtrinh2 Date: Fri, 8 Dec 2023 14:49:32 -0500 Subject: [PATCH] Merge feature/cicd into main (#9) * Create cicd--mv-website.yml github actions workflow to generate release on commit * Create Dockerfile this docker image, container will be used in cicd pipeline to generate the hugo website. * Update Dockerfile removed npm install * Update cicd--mv-website.yml http only for dev url --- .github/workflows/cicd--mv-website.yml | 95 ++++++++++++++++++++++++++ mv-website/Dockerfile | 15 ++++ 2 files changed, 110 insertions(+) create mode 100644 .github/workflows/cicd--mv-website.yml create mode 100644 mv-website/Dockerfile diff --git a/.github/workflows/cicd--mv-website.yml b/.github/workflows/cicd--mv-website.yml new file mode 100644 index 00000000..dccb9ae0 --- /dev/null +++ b/.github/workflows/cicd--mv-website.yml @@ -0,0 +1,95 @@ +name: "[mv-website] Build & Publish" + +on: + push: + branches: + - "feature/cicd" + - "main" + paths: + - "mv-website/**" + - ".github/workflows/cicd--mv-website.yml" +env: + REGISTRY: ghcr.io + IMAGE_NAME: "ghcr.io/${{ github.repository }}-website" + CONTEXT_ROOT: "mv-website" + DEVL_URL: "http://dev.earlymodernviolence.org/" + PROD_URL: "https://earlymodernviolence.org/" + +jobs: + build: + runs-on: ubuntu-latest + + permissions: + packages: write + + steps: + - uses: actions/checkout@v3 + + - name: Login to GitHub Container Registry + uses: docker/login-action@v2 + with: + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + registry: ${{ env.REGISTRY }} + + - name: Build and Push Docker Image for Local Dev + uses: docker/build-push-action@v4 + with: + context: "${{ env.CONTEXT_ROOT }}" + push: true + tags: "${{ env.IMAGE_NAME }}:latest" + platforms: linux/amd64 + + - name: Build Docker Image + uses: docker/build-push-action@v4 + with: + context: "${{ env.CONTEXT_ROOT }}" + push: false + tags: "${{ env.IMAGE_NAME }}:latest" + platforms: linux/amd64 + build-args: | + hugobuildargs=--cleanDestinationDir --buildDrafts --buildFuture --baseURL ${{ env.DEVL_URL }} + #hugobuildargs=--cleanDestinationDir --minify --baseURL ${{ env.PROD_URL }} + + - name: Extract build artifact from docker image + uses: shrink/actions-docker-extract@v2 + id: extract + with: + image: "${{ env.IMAGE_NAME }}:latest" + path: /usr/share/nginx/html/ + + - name: Archive build artifact + run: tar czvf mv-website.tar.gz -C ${{ steps.extract.outputs.destination }}/html . + + - name: Upload build artifact + uses: actions/upload-artifact@v3 + with: + path: ./mv-website.tar.gz + name: mv-website + + release: + needs: build + uses: chnm/.github/.github/workflows/create-release.yml@main + secrets: inherit + with: + github-run-id: "${{ github.run_id }}" + github-workflow: "${{ github.workflow }}" + github-workflow-ref: "${{ github.workflow_ref }}" + github-workflow-sha: "${{ github.workflow_sha }}" + github-workspace: "${{ github.workspace }}" + github-repository: "${{ github.repository }}" + github-repository-owner: "${{ github.repository_owner }}" + github-repository-name: "${{ github.event.repository.name }}" + github-repository-url: "${{ github.repository-url }}" + github-action-ref: "${{ github.action_ref }}" + github-event-name: "${{ github.event_name }}" + github-actor: "${{ github.actor }}" + github-triggering-actor: "${{ github.triggering_actor }}" + github-base-ref: "${{ github.base_ref }}" + github-ref-name: "${{ github.ref_name }}" + github-ref-type: "${{ github.ref_type }}" + github-ref: "${{ github.ref }}" + github-sha: "${{ github.sha }}" + build-artifact-name: "mv-website" + release-artifact-tarball-filename: "mv-website.tar.gz" + release-tag-name-type: "iso" diff --git a/mv-website/Dockerfile b/mv-website/Dockerfile new file mode 100644 index 00000000..80a37290 --- /dev/null +++ b/mv-website/Dockerfile @@ -0,0 +1,15 @@ +FROM klakegg/hugo:0.107.0-alpine as build-stage + +ARG hugobuildargs +ENV HUGO_BUILD_ARGS $hugobuildargs + +RUN apk add npm + +WORKDIR /app +ADD . . + +RUN hugo ${HUGO_BUILD_ARGS} + +FROM nginx:1.23-alpine + +COPY --from=build-stage /app/public/ /usr/share/nginx/html