build: add Dockerfile to run the project in container (#262)

* Dockerfile added to build static files and serve with NGINX Distroless

* replaced final image distroless with official nginx unprivileged to support multi arch.

* runtime image to official nginx

* README updated

* docs: update README for Docker commands

---------

Co-authored-by: satnaing <satnaingdev@gmail.com>
This commit is contained in:
Micheal Choudhary
2024-07-16 04:19:40 +02:00
committed by GitHub
parent b9266cb20d
commit 47a3c8651e
3 changed files with 43 additions and 1 deletions
+8
View File
@@ -0,0 +1,8 @@
# Ignore Astro files
*.astro
# Ignore node_modules directory
node_modules/
# Ignore build output
dist/
+12
View File
@@ -0,0 +1,12 @@
# Base stage for building the static files
FROM node:lts AS base
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build
# Runtime stage for serving the application
FROM nginx:mainline-alpine-slim AS runtime
COPY --from=base ./app/dist /usr/share/nginx/html
EXPOSE 80
+23 -1
View File
@@ -102,7 +102,7 @@ Documentation can be read in two formats\_ _markdown_ & _blog post_.
## 👨🏻‍💻 Running Locally
The easiest way to run this project locally is to run the following command in your desired directory.
You can start using this project locally by running the following command in your desired directory:
```bash
# npm 6.x
@@ -118,6 +118,26 @@ yarn create astro --template satnaing/astro-paper
pnpm dlx create-astro --template satnaing/astro-paper
```
Then start the project by running the following commands:
```bash
# prepare commit hook & install dependencies
npm run prepare && npm run install
# start running the project
npm run dev
```
As an alternative approach, if you have Docker installed, you can use Docker to run this project locally. Here's how:
```bash
# Build the Docker image
docker build -t astropaper .
# Run the Docker container
docker run -p 4321:80 astropaper
```
## Google Site Verification (optional)
You can easily add your [Google Site Verification HTML tag](https://support.google.com/webmasters/answer/9008080#meta_tag_verification&zippy=%2Chtml-tag) in AstroPaper using environment variable. This step is optional. If you don't add the following env variable, the google-site-verification tag won't appear in the html `<head>` section.
@@ -146,6 +166,8 @@ All commands are run from the root of the project, from a terminal:
| `npm run lint` | Lint with ESLint |
| `docker compose up -d` | Run AstroPaper on docker, You can access with the same hostname and port informed on `dev` command. |
| `docker compose run app npm install` | You can run any command above into the docker container. |
| `docker build -t astropaper .` | Build Docker image for AstroPaper. |
| `docker run -p 4321:80 astropaper` | Run AstroPaper on Docker. The website will be accessible at `http://localhost:4321`. |
> **_Warning!_** Windows PowerShell users may need to install the [concurrently package](https://www.npmjs.com/package/concurrently) if they want to [run diagnostics](https://docs.astro.build/en/reference/cli-reference/#astro-check) during development (`astro check --watch & astro dev`). For more info, see [this issue](https://github.com/satnaing/astro-paper/issues/113).