+7
-2
@@ -1,10 +1,15 @@
|
||||
FROM golang:1.25.5-alpine AS builder
|
||||
RUN apk add --no-cache build-base ca-certificates
|
||||
WORKDIR /app
|
||||
|
||||
COPY go.mod go.sum ./
|
||||
RUN go mod download
|
||||
RUN --mount=type=cache,target=/go/pkg/mod \
|
||||
go mod download
|
||||
|
||||
COPY . .
|
||||
RUN CGO_ENABLED=1 GOOS=linux go build -a -installsuffix cgo -o shagram ./cmd/server
|
||||
RUN --mount=type=cache,target=/go/pkg/mod \
|
||||
--mount=type=cache,target=/root/.cache/go-build \
|
||||
CGO_ENABLED=1 GOOS=linux go build -o shagram ./cmd/server
|
||||
|
||||
FROM alpine:latest
|
||||
RUN apk add --no-cache ca-certificates sqlite-libs sqlite
|
||||
|
||||
Vendored
+59
-43
@@ -1,45 +1,61 @@
|
||||
pipeline{
|
||||
agent { label 'docker' }
|
||||
options {
|
||||
skipDefaultCheckout()
|
||||
}
|
||||
environment {
|
||||
PROJECT_DIR = "/opt/shagram/shagram"
|
||||
IMAGE_NAME = "shagram"
|
||||
}
|
||||
stages{
|
||||
stage('Checkout') {
|
||||
steps {
|
||||
dir(env.PROJECT_DIR) {
|
||||
deleteDir()
|
||||
git url: 'https://github.com/emil28092005/shagram.git', branch: 'main'
|
||||
}
|
||||
}
|
||||
}
|
||||
stage('Build') {
|
||||
steps {
|
||||
dir(env.PROJECT_DIR) {
|
||||
echo 'Building shagram...'
|
||||
sh 'docker build -t ${IMAGE_NAME}:${GIT_COMMIT} .'
|
||||
pipeline {
|
||||
agent { label 'docker-agent' }
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
stage('Test') {
|
||||
steps {
|
||||
echo 'Testing...'
|
||||
sh 'docker run --rm ${IMAGE_NAME}:${GIT_COMMIT} sqlite3 --version'
|
||||
}
|
||||
}
|
||||
stage('Deploy') {
|
||||
steps {
|
||||
dir("${PROJECT_DIR}/deploy/shagram") {
|
||||
echo 'Deploying...'
|
||||
sh 'printf "APP_IMAGE=%s\\n" "${IMAGE_NAME}:${GIT_COMMIT}" > .env'
|
||||
sh 'docker compose up -d'
|
||||
sh 'docker compose ps'
|
||||
}
|
||||
}
|
||||
}
|
||||
options {
|
||||
skipDefaultCheckout(true)
|
||||
timestamps()
|
||||
}
|
||||
|
||||
environment {
|
||||
IMAGE_NAME = "shagram"
|
||||
DEPLOY_DIR = "/opt/shagram/shagram/deploy/shagram"
|
||||
COMPOSE_FILE = "/opt/shagram/shagram/deploy/shagram/compose.yaml"
|
||||
}
|
||||
|
||||
stages {
|
||||
stage('Checkout') {
|
||||
steps {
|
||||
checkout scm
|
||||
sh '''
|
||||
set -eux
|
||||
git reset --hard
|
||||
git clean -xffd
|
||||
'''
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stage('Build') {
|
||||
steps {
|
||||
script {
|
||||
env.GIT_SHA = sh(script: "git rev-parse --short HEAD", returnStdout: true).trim()
|
||||
env.APP_IMAGE = "${IMAGE_NAME}:${env.GIT_SHA}"
|
||||
}
|
||||
sh '''
|
||||
set -eux
|
||||
docker build -t "$APP_IMAGE" .
|
||||
'''
|
||||
}
|
||||
}
|
||||
|
||||
stage('Test') {
|
||||
steps {
|
||||
sh '''
|
||||
echo "Testing..."
|
||||
'''
|
||||
}
|
||||
}
|
||||
|
||||
stage('Deploy') {
|
||||
steps {
|
||||
sh '''
|
||||
set -eux
|
||||
mkdir -p "$DEPLOY_DIR"
|
||||
cat > "$DEPLOY_DIR/.env" <<EOF
|
||||
APP_IMAGE=$APP_IMAGE
|
||||
EOF
|
||||
docker compose -f "$COMPOSE_FILE" --project-directory "$DEPLOY_DIR" up -d --remove-orphans
|
||||
'''
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,9 @@ services:
|
||||
jenkins-agent-docker:
|
||||
image: jenkins/inbound-agent:latest-jdk17
|
||||
container_name: jenkins-agent-docker
|
||||
user: "1000:1000"
|
||||
group_add:
|
||||
- "988"
|
||||
environment:
|
||||
- JENKINS_URL=http://jenkins-controller:8080
|
||||
- JENKINS_AGENT_NAME=docker-agent
|
||||
@@ -22,6 +25,7 @@ services:
|
||||
- /usr/bin/docker:/usr/bin/docker
|
||||
- /usr/libexec/docker/cli-plugins:/usr/libexec/docker/cli-plugins:ro
|
||||
- /opt/shagram:/opt/shagram
|
||||
|
||||
restart: unless-stopped
|
||||
depends_on:
|
||||
- jenkins-controller
|
||||
|
||||
Reference in New Issue
Block a user