-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
pakizheng
committed
Jan 11, 2024
1 parent
39b7a6d
commit 19a5d4c
Showing
119 changed files
with
17,291 additions
and
637 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
name: Build and Deploy Docker Image | ||
|
||
on: | ||
push: | ||
branches: | ||
- master # 根据需要调整分支名称 | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v1 | ||
|
||
- name: Login to DockerHub | ||
uses: docker/login-action@v1 | ||
with: | ||
username: ${{ secrets.DOCKERHUB_USERNAME }} | ||
password: ${{ secrets.DOCKERHUB_TOKEN }} | ||
|
||
- name: Build and push Docker image | ||
uses: docker/build-push-action@v2 | ||
with: | ||
context: . | ||
push: true | ||
tags: zhengpq/im-web:latest | ||
build-args: | | ||
SECRET_ID=${{ secrets.SECRET_ID }} | ||
SECRET_KEY=${{ secrets.SECRET_KEY }} | ||
DB_NAME=${{ secrets.DB_NAME }} | ||
DB_USER_NAME=${{ secrets.DB_USER_NAME }} | ||
DB_PASSWORD=${{ secrets.DB_PASSWORD }} | ||
COS_BUCKET=${{ secrets.COS_BUCKET }} | ||
COS_REGION=${{ secrets.COS_REGION }} | ||
- name: Deploy to remote server | ||
env: | ||
SERVER_PASSWORD: ${{ secrets.SERVER_PASSWORD }} | ||
run: | | ||
sudo apt-get install -y sshpass | ||
sshpass -p "$SERVER_PASSWORD" ssh -o StrictHostKeyChecking=no root@${{ secrets.SERVER_ID }} " | ||
cd /root/dockers | ||
if docker ps -a --format "{{.Names}}" | grep -w "im-web"; then | ||
docker-compose down | ||
fi | ||
echo '${{ secrets.DOCKERHUB_TOKEN }}' | docker login --username zhengpq --password-stdin | ||
docker-compose pull | ||
docker-compose up -d | ||
" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# # syntax=docker/dockerfile:1 | ||
|
||
# # Comments are provided throughout this file to help you get started. | ||
# # If you need more help, visit the Dockerfile reference guide at | ||
# # https://docs.docker.com/go/dockerfile-reference/ | ||
|
||
# ARG NODE_VERSION=18.15.0 | ||
|
||
# FROM node:${NODE_VERSION}-alpine | ||
|
||
# # Use production node environment by default. | ||
# ENV NODE_ENV production | ||
|
||
|
||
# WORKDIR . | ||
|
||
# CMD npm install | ||
|
||
# # Download dependencies as a separate step to take advantage of Docker's caching. | ||
# # Leverage a cache mount to /root/.npm to speed up subsequent builds. | ||
# # Leverage a bind mounts to package.json and package-lock.json to avoid having to copy them into | ||
# # into this layer. | ||
# # RUN --mount=type=bind,source=package.json,target=package.json \ | ||
# # --mount=type=bind,source=package-lock.json,target=package-lock.json \ | ||
# # --mount=type=cache,target=/root/.npm \ | ||
# # npm ci --omit=dev | ||
|
||
# # Run the application as a non-root user. | ||
# USER node | ||
|
||
# # Copy the rest of the source files into the image. | ||
# # COPY . . | ||
|
||
# # Expose the port that the application listens on. | ||
# EXPOSE 8000 | ||
|
||
# # Run the application. | ||
# CMD npm run dev | ||
|
||
FROM node:18.15.0 | ||
|
||
EXPOSE 8000 | ||
|
||
WORKDIR /usr/src/app | ||
|
||
COPY package*.json ./ | ||
|
||
RUN npm install | ||
|
||
# 安装 PM2 | ||
RUN npm install pm2 -g | ||
|
||
# 复制项目源代码 | ||
COPY . . | ||
|
||
# 构建项目 | ||
RUN npm run build | ||
|
||
|
||
# 设置环境变量 | ||
ARG SECRET_ID | ||
ARG SECRET_KEY | ||
ARG DB_NAME | ||
ARG DB_USER_NAME | ||
ARG DB_PASSWORD | ||
ARG COS_BUCKET | ||
ARG COS_REGION | ||
ENV SECRET_ID=$SECRET_ID | ||
ENV SECRET_KEY=$SECRET_KEY | ||
ENV DB_NAME=$DB_NAME | ||
ENV DB_USER_NAME=$DB_USER_NAME | ||
ENV DB_PASSWORD=$DB_PASSWORD | ||
ENV COS_BUCKET=$COS_BUCKET | ||
ENV COS_REGION=$COS_REGION | ||
|
||
#CMD ["node", "main.js"] | ||
CMD ["pm2-runtime", "./ecosystem.config.js", "--env production"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
|
||
version: "3" | ||
|
||
services: | ||
im-web: | ||
image: zhengpq/im-web:latest | ||
container_name: im-web | ||
network_mode: "host" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
module.exports = { | ||
apps: [ | ||
{ | ||
name: 'im', | ||
script: './dist/main.js', | ||
env_production: { | ||
NODE_ENV: 'production', | ||
SECRET_ID: process.env.SECRET_ID, | ||
SECRET_KEY: process.env.SECRET_KEY, | ||
DB_NAME: process.env.DB_NAME, | ||
DB_USER_NAME: process.env.DB_USER_NAME, | ||
DB_PASSWORD: process.env.DB_PASSWORD, | ||
COS_BUCKET: process.env.COS_BUCKET, | ||
COS_REGION: process.env.COS_REGION, | ||
}, | ||
}, | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.