+7
-2
@@ -1,10 +1,15 @@
|
|||||||
FROM golang:1.25.5-alpine AS builder
|
FROM golang:1.25.5-alpine AS builder
|
||||||
RUN apk add --no-cache build-base ca-certificates
|
RUN apk add --no-cache build-base ca-certificates
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
COPY go.mod go.sum ./
|
COPY go.mod go.sum ./
|
||||||
RUN go mod download
|
RUN --mount=type=cache,target=/go/pkg/mod \
|
||||||
|
go mod download
|
||||||
|
|
||||||
COPY . .
|
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
|
FROM alpine:latest
|
||||||
RUN apk add --no-cache ca-certificates sqlite-libs sqlite
|
RUN apk add --no-cache ca-certificates sqlite-libs sqlite
|
||||||
|
|||||||
Vendored
+59
-43
@@ -1,45 +1,61 @@
|
|||||||
pipeline{
|
pipeline {
|
||||||
agent { label 'docker' }
|
agent { label 'docker-agent' }
|
||||||
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} .'
|
|
||||||
|
|
||||||
}
|
options {
|
||||||
}
|
skipDefaultCheckout(true)
|
||||||
}
|
timestamps()
|
||||||
stage('Test') {
|
}
|
||||||
steps {
|
|
||||||
echo 'Testing...'
|
environment {
|
||||||
sh 'docker run --rm ${IMAGE_NAME}:${GIT_COMMIT} sqlite3 --version'
|
IMAGE_NAME = "shagram"
|
||||||
}
|
DEPLOY_DIR = "/opt/shagram/shagram/deploy/shagram"
|
||||||
}
|
COMPOSE_FILE = "/opt/shagram/shagram/deploy/shagram/compose.yaml"
|
||||||
stage('Deploy') {
|
}
|
||||||
steps {
|
|
||||||
dir("${PROJECT_DIR}/deploy/shagram") {
|
stages {
|
||||||
echo 'Deploying...'
|
stage('Checkout') {
|
||||||
sh 'printf "APP_IMAGE=%s\\n" "${IMAGE_NAME}:${GIT_COMMIT}" > .env'
|
steps {
|
||||||
sh 'docker compose up -d'
|
checkout scm
|
||||||
sh 'docker compose ps'
|
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:
|
jenkins-agent-docker:
|
||||||
image: jenkins/inbound-agent:latest-jdk17
|
image: jenkins/inbound-agent:latest-jdk17
|
||||||
container_name: jenkins-agent-docker
|
container_name: jenkins-agent-docker
|
||||||
|
user: "1000:1000"
|
||||||
|
group_add:
|
||||||
|
- "988"
|
||||||
environment:
|
environment:
|
||||||
- JENKINS_URL=http://jenkins-controller:8080
|
- JENKINS_URL=http://jenkins-controller:8080
|
||||||
- JENKINS_AGENT_NAME=docker-agent
|
- JENKINS_AGENT_NAME=docker-agent
|
||||||
@@ -22,6 +25,7 @@ services:
|
|||||||
- /usr/bin/docker:/usr/bin/docker
|
- /usr/bin/docker:/usr/bin/docker
|
||||||
- /usr/libexec/docker/cli-plugins:/usr/libexec/docker/cli-plugins:ro
|
- /usr/libexec/docker/cli-plugins:/usr/libexec/docker/cli-plugins:ro
|
||||||
- /opt/shagram:/opt/shagram
|
- /opt/shagram:/opt/shagram
|
||||||
|
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
depends_on:
|
depends_on:
|
||||||
- jenkins-controller
|
- jenkins-controller
|
||||||
|
|||||||
Reference in New Issue
Block a user