Skip to content

Commit

Permalink
CI/CD
Browse files Browse the repository at this point in the history
  • Loading branch information
M397749490 committed Nov 19, 2024
1 parent 54170a2 commit 0f6ffee
Show file tree
Hide file tree
Showing 5 changed files with 1,154 additions and 1,189 deletions.
22 changes: 10 additions & 12 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ name: CI/CD

on:
push:
branches:
- "main"
- "feat-user-manage"
branches: ["main", "feat-user-manage"]
workflow_dispatch:

jobs:
Expand All @@ -21,8 +19,8 @@ jobs:
- name: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
username: ${{ vars.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Build and push
id: docker_build
uses: docker/build-push-action@v4
Expand All @@ -31,7 +29,7 @@ jobs:
push: true
platforms: linux/amd64
tags: |
${{ secrets.DOCKERHUB_USERNAME }}/klpbbs-survey-frontend:${{ github.ref == 'refs/heads/main' && 'latest' || 'user' }}
${{ vars.DOCKERHUB_USERNAME }}/${{ vars.IMAGE_NAME }}:${{ github.ref == 'refs/heads/main' && 'latest' || 'user' }}
cache-from: type=gha
cache-to: type=gha,mode=max

Expand All @@ -44,19 +42,19 @@ jobs:
- name: Login to ACR
uses: aliyun/acr-login@v1
with:
login-server: https://registry.cn-guangzhou.aliyuncs.com
username: "${{ secrets.REGISTRY_USERNAME }}"
login-server: https://${{ vars.REGISTRY_ADDRESS }}
username: "${{ vars.REGISTRY_USERNAME }}"
password: "${{ secrets.REGISTRY_PASSWORD }}"
- name: Build and push image
run: |
docker build -t registry.cn-guangzhou.aliyuncs.com/teamvastsea/klpbbs-survey-frontend:${{ github.ref == 'refs/heads/main' && 'latest' || 'user' }} .
docker push registry.cn-guangzhou.aliyuncs.com/teamvastsea/klpbbs-survey-frontend:${{ github.ref == 'refs/heads/main' && 'latest' || 'user' }}
docker build -t ${{ vars.REGISTRY_ADDRESS }}/${{ vars.REGISTRY_NAMESPACE }}/${{ vars.IMAGE_NAME }}:latest .
docker push ${{ vars.REGISTRY_ADDRESS }}/${{ vars.REGISTRY_NAMESPACE }}/${{ vars.IMAGE_NAME }}:latest
deploy:
name: Deploy
needs: [build_docker, build_docker_acr]
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main' # Only run deploy if on main branch
if: github.ref == 'refs/heads/main'
steps:
- name: SSH To Host
uses: appleboy/[email protected]
Expand All @@ -66,5 +64,5 @@ jobs:
key: ${{ secrets.SSH_KEY }}
port: ${{ secrets.SSH_PORT }}
script: |
cd ${{ secrets.PROJ_PATH }}
cd ${{ secrets.PROJECT_PATH }}
sudo bash ./deploy.sh
0 LICENCE → LICENSE
100755 → 100644
File renamed without changes.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Using this system, KLPBBS users can quickly log in using their KLPBBS account wi

## Licence

This project is licensed under the MIT license, please refer to [LICENCE](./LICENSE) for details
This project is licensed under the MIT license, please refer to [LICENSE](./LICENSE) for details

## Contribute

Expand Down
46 changes: 41 additions & 5 deletions dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,46 @@
FROM node:21-alpine3.18
FROM node:18-alpine AS base

FROM base AS deps
RUN apk add --no-cache libc6-compat
WORKDIR /app

ADD . .
COPY package.json yarn.lock ./
RUN \
if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
else echo "Lockfile not found." && exit 1; \
fi

RUN yarn install && \
yarn build
FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .

RUN \
if [ -f yarn.lock ]; then yarn run build; \
else echo "Lockfile not found." && exit 1; \
fi

FROM base AS runner
WORKDIR /app

ENV NODE_ENV=production

RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs

COPY --from=builder /app/public ./public

RUN mkdir .next
RUN chown nextjs:nodejs .next

COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static

USER nextjs

EXPOSE 3000

ENV PORT=3000

CMD [ "yarn", "start" ]
ENV HOSTNAME="0.0.0.0"
CMD ["node", "server.js"]
Loading

0 comments on commit 0f6ffee

Please sign in to comment.