Skip to content

Commit

Permalink
Merge branch 'docker'
Browse files Browse the repository at this point in the history
  • Loading branch information
ccbikai committed Aug 31, 2024
2 parents dcaa3eb + d2b6324 commit 5490640
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 15 deletions.
6 changes: 6 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.DS_Store
node_modules
dist
.git
.gitignore
*.md
8 changes: 4 additions & 4 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ HEADER_INJECT=HEADER_INJECT
NO_FOLLOW=false
NO_INDEX=false

SENTRY_AUTH_TOKEN=SENTRY_AUTH_TOKEN
SENTRY_DSN=SENTRY_DSN
SENTRY_PROJECT=SENTRY_PROJECT
SENTRY_AUTH_TOKEN=
SENTRY_DSN=
SENTRY_PROJECT=

HOST=telegram.dog
TELEGRAM_HOST=telegram.dog
STATIC_PROXY=""
57 changes: 57 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Docker build and push workflow
name: Create and publish a Docker image

# Triggered by workflow_dispatch
on:
workflow_dispatch:

# Defines two custom environment variables for the workflow. These are used for the Container registry domain, and a name for the Docker image that this workflow builds.
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

# There is a single job in this workflow. It's configured to run on the latest available version of Ubuntu.
jobs:
build-and-push-image:
runs-on: ubuntu-latest
# Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job.
permissions:
contents: read
packages: write
attestations: write
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
# Uses the `docker/login-action` action to log in to the Container registry registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here.
- name: Log in to the Container registry
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) to extract tags and labels that will be applied to the specified image. The `id` "meta" allows the output of this step to be referenced in a subsequent step. The `images` value provides the base name for the tags and labels.
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
# This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages.
# It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see "[Usage](https://github.com/docker/build-push-action#usage)" in the README of the `docker/build-push-action` repository.
# It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step.
- name: Build and push Docker image
id: push
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

# This step generates an artifact attestation for the image, which is an unforgeable statement about where and how it was built. It increases supply chain security for people who consume the image. For more information, see "[AUTOTITLE](/actions/security-guides/using-artifact-attestations-to-establish-provenance-for-builds)."
- name: Generate artifact attestation
uses: actions/attest-build-provenance@v1
with:
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
subject-digest: ${{ steps.push.outputs.digest }}
push-to-registry: true
27 changes: 27 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
FROM node:lts-alpine AS base

ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
RUN corepack enable

WORKDIR /app
COPY package.json pnpm-lock.yaml ./

# FROM base AS prod-deps
# RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --prod --frozen-lockfile

FROM base AS build-deps
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile

FROM build-deps AS build
COPY . .
RUN export $(cat .env.example) && export DOCKER=true && pnpm run build

FROM base AS runtime
# COPY --from=prod-deps /app/node_modules ./node_modules
COPY --from=build /app/dist ./dist

ENV HOST=0.0.0.0
ENV PORT=4321
EXPOSE 4321
CMD node ./dist/server/entry.mjs
1 change: 1 addition & 0 deletions astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export default defineConfig({
],
vite: {
ssr: {
noExternal: process.env.DOCKER ? !!process.env.DOCKER : undefined,
external: [
...adapterProvider === 'cloudflare_pages'
? [
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@
"astro": "astro",
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"postinstall": "simple-git-hooks"
"postinstall": "test -d .git && simple-git-hooks || true"
},
"dependencies": {
"@astrojs/rss": "^4.0.7",
"@sentry/astro": "^8.26.0",
"astro": "^4.14.5",
"astro-seo": "^0.8.4",
"cheerio": "1.0.0-rc.12",
"dayjs": "^1.11.13",
"flourite": "^1.3.0",
Expand All @@ -35,7 +33,9 @@
"@astrojs/node": "^8.3.3",
"@astrojs/vercel": "^7.8.0",
"@types/prismjs": "^1.26.4",
"astro": "^4.14.5",
"astro-eslint-parser": "^1.0.2",
"astro-seo": "^0.8.4",
"autoprefixer": "^10.4.20",
"cssnano": "^7.0.5",
"eslint": "9.5.0",
Expand Down
14 changes: 7 additions & 7 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/lib/telegram/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ export async function getChannelInfo(Astro, { before = '', after = '', q = '', t
}

// Where t.me can also be telegram.me, telegram.dog
const host = getEnv(import.meta.env, Astro, 'HOST') ?? 't.me'
const host = getEnv(import.meta.env, Astro, 'TELEGRAM_HOST') ?? 't.me'
const channel = getEnv(import.meta.env, Astro, 'CHANNEL')
const staticProxy = getEnv(import.meta.env, Astro, 'STATIC_PROXY') ?? '/static/'

Expand Down

0 comments on commit 5490640

Please sign in to comment.