Skip to content

Commit

Permalink
update dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
Sianao committed Nov 24, 2024
1 parent e2e9cc8 commit d15128d
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 21 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/golang.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: hexo-ci
on:
push:
branches: main
env:
IMAGE_NAME: gitproxy
jobs:
build:
runs-on: ubuntu-latest
permissions:
packages: write
contents: read

steps:
- name: checkout
uses: actions/checkout@master

- name: build
run: |
docker build . --file Dockerfile --tag $IMAGE_NAME --label "runnumber=${GITHUB_RUN_ID}"
echo "${{ secrets.GITHUB_TOKEN }}"
echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
- name: push
run: |
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
VERSION=$(echo "${{ github.sha }}" | sed -e 's,.*/\(.*\),\1,')
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
docker push $IMAGE_ID:$VERSION
echo IMAGE_ID=$IMAGE_ID
echo VERSION=$VERSION

40 changes: 19 additions & 21 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
FROM docker.io/node:alpine AS deps
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
RUN apk add --no-cache libc6-compat
RUN yarn config set registry https://registry.npmmirror.com
WORKDIR /app
COPY package.json yarn.lock ./
COPY package.json ./
RUN yarn install --frozen-lockfile

# Rebuild the source code only when needed
Expand All @@ -13,31 +14,28 @@ COPY . .
COPY --from=deps /app/node_modules ./node_modules
RUN yarn build && yarn install --production --ignore-scripts --prefer-offline

# Production image, copy all the files and run next
FROM docker.io/node:alpine AS runner
WORKDIR /app
FROM golang:alpine AS Gobuilder

LABEL stage=gobuilder

ENV NODE_ENV production
ENV CGO_ENABLED 0

RUN addgroup -g 1001 -S nodejs
RUN adduser -S nextjs -u 1001
RUN apk update --no-cache && apk add --no-cache tzdata

# You only need to copy next.config.js if you are NOT using the default configuration
# COPY --from=builder /app/next.config.js ./
COPY --from=builder /app/public ./public
COPY --from=builder --chown=nextjs:nodejs /app/.next ./.next
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/package.json ./package.json
WORKDIR /build

USER nextjs
ADD go.mod .
ADD go.sum .
RUN go mod download
COPY . .
RUN go build -ldflags="-s -w" -o /app/gitproxy main.go

EXPOSE 3000

ENV PORT 3000
FROM busybox

# Next.js collects completely anonymous telemetry data about general usage.
# Learn more here: https://nextjs.org/telemetry
# Uncomment the following line in case you want to disable telemetry.
# ENV NEXT_TELEMETRY_DISABLED 1
ENV TZ Asia/Shanghai

CMD ["node_modules/.bin/next", "start"]
WORKDIR /app
COPY --from=Gobuilder /app/gitproxy /app/gitproxy
COPY --from=builder /app/out /app/
CMD ["./gitproxy"]

0 comments on commit d15128d

Please sign in to comment.