Set up Harbor.
This commit is contained in:
Vendored
+26
-5
@@ -7,6 +7,8 @@ pipeline {
|
|||||||
}
|
}
|
||||||
|
|
||||||
environment {
|
environment {
|
||||||
|
REGISTRY = "10.129.0.7:8085"
|
||||||
|
REGISTRY_PROJECT = "shagram"
|
||||||
IMAGE_NAME = "shagram"
|
IMAGE_NAME = "shagram"
|
||||||
DEPLOY_DIR = "/opt/shagram/shagram/deploy/shagram"
|
DEPLOY_DIR = "/opt/shagram/shagram/deploy/shagram"
|
||||||
COMPOSE_FILE = "${WORKSPACE}/deploy/shagram/compose.yaml"
|
COMPOSE_FILE = "${WORKSPACE}/deploy/shagram/compose.yaml"
|
||||||
@@ -27,7 +29,6 @@ pipeline {
|
|||||||
stage('Detect branch') {
|
stage('Detect branch') {
|
||||||
steps {
|
steps {
|
||||||
script {
|
script {
|
||||||
|
|
||||||
env.GIT_BRANCH = sh(
|
env.GIT_BRANCH = sh(
|
||||||
script: "git name-rev --name-only --refs=refs/remotes/origin/* HEAD | sed 's#^remotes/##' | head -n1",
|
script: "git name-rev --name-only --refs=refs/remotes/origin/* HEAD | sed 's#^remotes/##' | head -n1",
|
||||||
returnStdout: true
|
returnStdout: true
|
||||||
@@ -37,19 +38,38 @@ pipeline {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stage('Build') {
|
stage('Build image') {
|
||||||
steps {
|
steps {
|
||||||
script {
|
script {
|
||||||
env.GIT_SHA = sh(script: "git rev-parse --short HEAD", returnStdout: true).trim()
|
env.GIT_SHA = sh(script: "git rev-parse --short HEAD", returnStdout: true).trim()
|
||||||
env.APP_IMAGE = "${IMAGE_NAME}:${env.GIT_SHA}"
|
// итоговый тег для Harbor
|
||||||
|
env.APP_IMAGE = "${REGISTRY}/${REGISTRY_PROJECT}/${IMAGE_NAME}:${env.GIT_SHA}"
|
||||||
}
|
}
|
||||||
sh '''
|
sh '''
|
||||||
set -eux
|
set -eux
|
||||||
docker build -t "$APP_IMAGE" .
|
# собираем локальный образ без registry
|
||||||
|
docker build -t "${IMAGE_NAME}:${GIT_SHA}" .
|
||||||
'''
|
'''
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
stage('Login & Push to Harbor') {
|
||||||
|
steps {
|
||||||
|
withCredentials([usernamePassword(
|
||||||
|
credentialsId: 'harbor-creds',
|
||||||
|
usernameVariable: 'HARBOR_USER',
|
||||||
|
passwordVariable: 'HARBOR_PASS'
|
||||||
|
)]) {
|
||||||
|
sh '''
|
||||||
|
set -eux
|
||||||
|
echo "$HARBOR_PASS" | docker login "$REGISTRY" -u "$HARBOR_USER" --password-stdin
|
||||||
|
docker tag "${IMAGE_NAME}:${GIT_SHA}" "${APP_IMAGE}"
|
||||||
|
docker push "${APP_IMAGE}"
|
||||||
|
'''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
stage('Test') {
|
stage('Test') {
|
||||||
steps {
|
steps {
|
||||||
sh 'echo "Testing..."'
|
sh 'echo "Testing..."'
|
||||||
@@ -66,9 +86,10 @@ pipeline {
|
|||||||
|
|
||||||
mkdir -p "$DEPLOY_DIR"
|
mkdir -p "$DEPLOY_DIR"
|
||||||
cat > "$DEPLOY_DIR/.env" <<EOF
|
cat > "$DEPLOY_DIR/.env" <<EOF
|
||||||
APP_IMAGE=$APP_IMAGE
|
APP_IMAGE=${APP_IMAGE}
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
docker compose -f "$COMPOSE_FILE" --project-directory "$DEPLOY_DIR" pull
|
||||||
docker compose -f "$COMPOSE_FILE" --project-directory "$DEPLOY_DIR" up -d --remove-orphans
|
docker compose -f "$COMPOSE_FILE" --project-directory "$DEPLOY_DIR" up -d --remove-orphans
|
||||||
docker compose -f "$COMPOSE_FILE" --project-directory "$DEPLOY_DIR" ps
|
docker compose -f "$COMPOSE_FILE" --project-directory "$DEPLOY_DIR" ps
|
||||||
'''
|
'''
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
services:
|
services:
|
||||||
shagram:
|
shagram:
|
||||||
image: ${APP_IMAGE:-shagram:local}
|
image: ${APP_IMAGE:-shagram:local}
|
||||||
build:
|
build:
|
||||||
context: ../..
|
context: ../..
|
||||||
container_name: shagram-app
|
container_name: shagram-app
|
||||||
environment:
|
environment:
|
||||||
@@ -10,7 +10,7 @@ services:
|
|||||||
- shagram_data:/app/data
|
- shagram_data:/app/data
|
||||||
expose:
|
expose:
|
||||||
- "8080"
|
- "8080"
|
||||||
|
|
||||||
nginx:
|
nginx:
|
||||||
image: nginx:alpine
|
image: nginx:alpine
|
||||||
container_name: shagram-nginx
|
container_name: shagram-nginx
|
||||||
@@ -23,4 +23,4 @@ services:
|
|||||||
depends_on:
|
depends_on:
|
||||||
- shagram
|
- shagram
|
||||||
volumes:
|
volumes:
|
||||||
shagram_data:
|
shagram_data:
|
||||||
|
|||||||
Reference in New Issue
Block a user