-
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
1021104
commit ccad5a2
Showing
44 changed files
with
160 additions
and
25 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
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: ${{ secrets.DOCKERHUB_USERNAME }}/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 }} " | ||
docker stop im-web | ||
docker rm im-web | ||
echo '${{ secrets.DOCKERHUB_TOKEN }}' | docker login --username ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin | ||
docker pull ${{ secrets.DOCKER_USER_NAME }}/im-web:latest | ||
docker run -d -p 3000:3000 --name im-web ${{ secrets.DOCKER_USER_NAME }}/im-web:latest | ||
" |
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,72 @@ | ||
# # 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 8001 | ||
|
||
# 先安装npm依赖,因为源代码变更很频繁 | ||
COPY package.json / | ||
# COPY package-lock.json / | ||
RUN npm install | ||
RUN npm run build | ||
|
||
# 安装 PM2 | ||
RUN npm install pm2 -g | ||
|
||
COPY . / | ||
|
||
# 设置环境变量 | ||
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,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
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
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
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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