Implement deploy strategy for local development; refactor container to use startup script.
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
tmp
|
||||
@@ -7,8 +7,11 @@ steps:
|
||||
password:
|
||||
from_secret: REGISTRY_PASSWORD
|
||||
registry: registry.binderlab.io
|
||||
repo: registry.binderlab.io/harbormaster
|
||||
repo: registry.binderlab.io/harbormaster-server
|
||||
tags: latest
|
||||
file: docker/Dockerfile
|
||||
context: .
|
||||
push: true
|
||||
when:
|
||||
event: manual
|
||||
|
||||
@@ -19,19 +22,22 @@ steps:
|
||||
from_secret: REGISTRY_USERNAME
|
||||
REGISTRY_PASSWORD:
|
||||
from_secret: REGISTRY_PASSWORD
|
||||
RESET_DB:
|
||||
from_secret: RESET_DB
|
||||
settings:
|
||||
host: binderlab.io
|
||||
username: binderb
|
||||
envs:
|
||||
- REGISTRY_USERNAME
|
||||
- REGISTRY_PASSWORD
|
||||
- RESET_DB
|
||||
key:
|
||||
from_secret: SSH_PRIVATE_KEY
|
||||
script:
|
||||
- echo "$REGISTRY_PASSWORD" | docker login registry.binderlab.io --username "$REGISTRY_USERNAME" --password-stdin
|
||||
- docker pull registry.binderlab.io/harbormaster:latest
|
||||
- docker pull registry.binderlab.io/harbormaster-server:latest
|
||||
- docker stop harbormaster || true
|
||||
- docker rm harbormaster || true
|
||||
- docker run -d --name harbormaster -p 7080:8080 registry.binderlab.io/harbormaster:latest
|
||||
- docker run -d --name harbormaster -p 7080:8080 -e RESET_DB $RESET_DB registry.binderlab.io/harbormaster:latest
|
||||
when:
|
||||
event: manual
|
||||
32
Dockerfile
32
Dockerfile
@@ -1,32 +0,0 @@
|
||||
# Use a small Go base image
|
||||
FROM golang:1.24 as builder
|
||||
|
||||
# Set working directory
|
||||
WORKDIR /app
|
||||
|
||||
# Copy go mod and sum files
|
||||
COPY go.mod go.sum ./
|
||||
|
||||
# Download dependencies
|
||||
RUN go mod download
|
||||
|
||||
# Copy the rest of the application
|
||||
COPY . .
|
||||
|
||||
# Build the application
|
||||
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o harbormaster .
|
||||
|
||||
# Use a small base image for the final container
|
||||
FROM alpine:latest
|
||||
|
||||
# Set working directory
|
||||
WORKDIR /root/
|
||||
|
||||
# Copy the compiled binary from the builder stage
|
||||
COPY --from=builder /app/harbormaster .
|
||||
|
||||
# Expose the port the app runs on
|
||||
EXPOSE 8080
|
||||
|
||||
# Run the binary
|
||||
CMD ["/root/harbormaster"]
|
||||
38
docker/Dockerfile
Normal file
38
docker/Dockerfile
Normal file
@@ -0,0 +1,38 @@
|
||||
# Use a small Go base image
|
||||
FROM golang:1.24 AS builder
|
||||
|
||||
# Set working directory
|
||||
WORKDIR /root
|
||||
|
||||
# Copy go mod and sum files
|
||||
COPY ../go.mod ../go.sum ./
|
||||
|
||||
# Download dependencies
|
||||
RUN go mod download
|
||||
|
||||
# Copy the rest of the application
|
||||
COPY ../src/ ./src/
|
||||
COPY ../scripts/ ./scripts/
|
||||
RUN chmod +x /root/scripts/startup.sh
|
||||
|
||||
# Build the application
|
||||
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o harbormaster ./src/
|
||||
|
||||
# Use a small base image for the final container
|
||||
FROM alpine:latest
|
||||
|
||||
# Set working directory
|
||||
WORKDIR /root
|
||||
|
||||
# Copy the compiled binary from the builder stage
|
||||
COPY --from=builder /root/harbormaster .
|
||||
#COPY database/gold.db /root/database/gold.db
|
||||
#COPY migrations /root/migrations
|
||||
COPY ../scripts/ /root/scripts/
|
||||
RUN chmod +x /root/scripts/startup.sh
|
||||
|
||||
# Expose the port the app runs on
|
||||
EXPOSE 8080
|
||||
|
||||
# Run database setup and the binary
|
||||
CMD ["/bin/ash", "-c", "/root/scripts/startup.sh"]
|
||||
17
docker/docker-compose.dev.yml
Normal file
17
docker/docker-compose.dev.yml
Normal file
@@ -0,0 +1,17 @@
|
||||
services:
|
||||
app:
|
||||
container_name: harbormaster-server
|
||||
image: harbormaster-server
|
||||
build:
|
||||
context: ..
|
||||
dockerfile: docker/Dockerfile
|
||||
target: builder
|
||||
volumes:
|
||||
- ../src:/root/src
|
||||
- ../scripts:/root/scripts
|
||||
ports:
|
||||
- "7080:8080"
|
||||
environment:
|
||||
- ENV=development
|
||||
# command: ["./harbormaster"]
|
||||
command: ["/bin/bash","/root/scripts/startup.sh"]
|
||||
12
scripts/dev.sh
Executable file
12
scripts/dev.sh
Executable file
@@ -0,0 +1,12 @@
|
||||
#!/bin/bash
|
||||
# cleanup() {
|
||||
# echo "Stopping Docker containers..."
|
||||
# docker-compose down
|
||||
# }
|
||||
|
||||
# trap cleanup EXIT SIGINT SIGTERM
|
||||
cd ../
|
||||
echo "Starting application..."
|
||||
docker compose -p harbormaster-server -f docker/docker-compose.dev.yml up -d --build
|
||||
echo "Tailing logs..."
|
||||
docker logs harbormaster-server -f
|
||||
6
scripts/startup.sh
Executable file
6
scripts/startup.sh
Executable file
@@ -0,0 +1,6 @@
|
||||
#!/bin/bash
|
||||
cd /root
|
||||
|
||||
echo "Starting application..."
|
||||
chmod +x ./harbormaster
|
||||
./harbormaster
|
||||
Reference in New Issue
Block a user