The flow chart

nuxt Dockerfile

FROM node:lts-alpine

LABEL Author=echo

# ENV NODE_ENV=production

ENV HOST=0.0.0.0



RUNmkdir -p /app

COPY. /app

WORKDIR/app



EXPOSE 22322



RUN yarn config set registry https://registry.npm.taobao.org/

RUNyarn install

RUNyarn run build



CMD ["yarn"."start"]



Copy the code

2 Jenkins configuration

Build

Execute shell

#! /bin/bash

Docker login -u -p [harbor address]

IMAGE_NAME="[mirror name]:$[$(date +%s%N)/ 1000000]"

echo $IMAGE_NAME

docker build --pull --rm -f "Dockerfile" -t $IMAGE_NAME "."

echo "==========Docker image built =========="

docker push $IMAGE_NAME

echo "==========Docker image push complete =========="

docker image rm $IMAGE_NAME

echo "==========Docker image deleted successfully =========="

Copy the code

Execute shell script on remote host using ssh

#! /bin/bash

Docker login -u -p [harbor address]

IMAGE_NAME=[Mirror name]

IMAGE_TAG=$(curl -u [harbor id] -x GET"Http:// [harbor address] / API/v2.0 / projects/vertex/repositories/vertex - web/artifacts? page=1&page_size=1&with_tag=true&with_label=false&with_scan_overview=false&with_signature=false&with_immutable_status=fa lse" -H "accept: application/json" | sed 's/,/\n/g' | grep "name" | awk -F ':' '{print $2}' | sed 's/"//g')

CONTAINER_ID=`docker ps | grep [docker name] | awk '{print $1}'`

echo $CONTAINER_ID

if [ -n "$CONTAINER_ID" ]

then

    docker rm -f $CONTAINER_ID

fi



IMAGE_ID=`docker images | grep "vertex-web" | awk '{print $3}'`

if [ -n "$IMAGE_ID" ]

then

    docker image rm $IMAGE_ID

fi

docker run --rm -p 22322:22322 -d --name [docker name] $IMAGE_NAME:$IMAGE_TAG



Copy the code