Set up Harbor.
This commit is contained in:
Vendored
+26
-5
@@ -7,6 +7,8 @@ pipeline {
|
||||
}
|
||||
|
||||
environment {
|
||||
REGISTRY = "10.129.0.7:8085"
|
||||
REGISTRY_PROJECT = "shagram"
|
||||
IMAGE_NAME = "shagram"
|
||||
DEPLOY_DIR = "/opt/shagram/shagram/deploy/shagram"
|
||||
COMPOSE_FILE = "${WORKSPACE}/deploy/shagram/compose.yaml"
|
||||
@@ -27,7 +29,6 @@ pipeline {
|
||||
stage('Detect branch') {
|
||||
steps {
|
||||
script {
|
||||
|
||||
env.GIT_BRANCH = sh(
|
||||
script: "git name-rev --name-only --refs=refs/remotes/origin/* HEAD | sed 's#^remotes/##' | head -n1",
|
||||
returnStdout: true
|
||||
@@ -37,19 +38,38 @@ pipeline {
|
||||
}
|
||||
}
|
||||
|
||||
stage('Build') {
|
||||
stage('Build image') {
|
||||
steps {
|
||||
script {
|
||||
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 '''
|
||||
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') {
|
||||
steps {
|
||||
sh 'echo "Testing..."'
|
||||
@@ -66,9 +86,10 @@ pipeline {
|
||||
|
||||
mkdir -p "$DEPLOY_DIR"
|
||||
cat > "$DEPLOY_DIR/.env" <<EOF
|
||||
APP_IMAGE=$APP_IMAGE
|
||||
APP_IMAGE=${APP_IMAGE}
|
||||
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" ps
|
||||
'''
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
services:
|
||||
shagram:
|
||||
image: ${APP_IMAGE:-shagram:local}
|
||||
build:
|
||||
build:
|
||||
context: ../..
|
||||
container_name: shagram-app
|
||||
environment:
|
||||
@@ -10,7 +10,7 @@ services:
|
||||
- shagram_data:/app/data
|
||||
expose:
|
||||
- "8080"
|
||||
|
||||
|
||||
nginx:
|
||||
image: nginx:alpine
|
||||
container_name: shagram-nginx
|
||||
@@ -23,4 +23,4 @@ services:
|
||||
depends_on:
|
||||
- shagram
|
||||
volumes:
|
||||
shagram_data:
|
||||
shagram_data:
|
||||
|
||||
Reference in New Issue
Block a user