Cleanup for some CI automation because one-offs justify automation.
This commit is contained in:
parent
3ea64f2fb6
commit
706e31f0b4
|
@ -0,0 +1,9 @@
|
|||
FROM golang:1.18 as builder
|
||||
WORKDIR /app
|
||||
COPY go.mod go.sum ./
|
||||
RUN go mod download
|
||||
COPY . .
|
||||
RUN ./build.sh
|
||||
FROM scratch
|
||||
COPY --from=builder /app/dist/imap-json-fetcher /imap-json-fetcher
|
||||
ENTRYPOINT ["/imap-json-fetcher"]
|
|
@ -0,0 +1 @@
|
|||
FROM git.nixc.us/colin/imap-json-fetcher:staging
|
30
build.sh
30
build.sh
|
@ -15,7 +15,7 @@ prepare_build() {
|
|||
# Initialize go modules if go.mod does not exist
|
||||
if [ ! -f go.mod ]; then
|
||||
echo "Initializing Go modules"
|
||||
go mod init imap-json-fetcher # Replace 'yourmodule' with your actual module name or path
|
||||
go mod init imap-json-fetcher # Adjust the module name as needed
|
||||
fi
|
||||
|
||||
# Fetch and ensure all dependencies are up to date
|
||||
|
@ -25,46 +25,34 @@ prepare_build() {
|
|||
|
||||
# Build function
|
||||
build_binary() {
|
||||
os=$1
|
||||
arch=$2
|
||||
output_name="imap-json-fetcher"
|
||||
local os=$1
|
||||
local arch=$2
|
||||
local output_name="imap-json-fetcher"
|
||||
|
||||
# Adjust output name for non-default architectures
|
||||
if [[ "$os/$arch" != "$DEFAULT_ARCH" ]]; then
|
||||
output_name="${output_name}_${os}_${arch}"
|
||||
fi
|
||||
|
||||
output_name="dist/${output_name}"
|
||||
|
||||
# Dynamic Linking
|
||||
echo "Building dynamically linked for ${os}/${arch} -> ${output_name}"
|
||||
GOOS=${os} GOARCH=${arch} go build -o ${output_name} main.go 2>build_logs/${os}_${arch}_build.log
|
||||
# Build both dynamic and static binaries as needed
|
||||
echo "Building for ${os}/${arch} -> ${output_name}"
|
||||
CGO_ENABLED=0 GOOS=${os} GOARCH=${arch} go build -a -ldflags '-extldflags "-static"' -o ${output_name} main.go 2>build_logs/${os}_${arch}_build.log
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "Successfully built ${output_name}"
|
||||
else
|
||||
echo "Failed to build ${output_name}. Check build_logs/${os}_${arch}_build.log for errors."
|
||||
fi
|
||||
|
||||
# Static Linking
|
||||
if [[ "$os" == "linux" ]]; then # Typically, static linking is most relevant for Linux environments
|
||||
static_output_name="${output_name}_static"
|
||||
echo "Building statically linked for ${os}/${arch} -> ${static_output_name}"
|
||||
CGO_ENABLED=0 GOOS=${os} GOARCH=${arch} go build -a -ldflags '-extldflags "-static"' -o ${static_output_name} main.go 2>build_logs/${os}_${arch}_static_build.log
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "Successfully built ${static_output_name}"
|
||||
else
|
||||
echo "Failed to build ${static_output_name}. Check build_logs/${os}_${arch}_static_build.log for errors."
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# Main Build Process
|
||||
prepare_build
|
||||
for arch in "${ARCHITECTURES[@]}"; do
|
||||
IFS='/' read -r -a parts <<< "$arch" # Split architecture string
|
||||
IFS='/' read -r -a parts <<< "$arch" # Split architecture string into OS and arch
|
||||
os=${parts[0]}
|
||||
arch=${parts[1]}
|
||||
build_binary $os $arch
|
||||
done
|
||||
|
||||
echo "Build process completed."
|
||||
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
services:
|
||||
imap-json-fetcher:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile.production
|
||||
image: git.nixc.us/colin/imap-json-fetcher:production
|
|
@ -0,0 +1,6 @@
|
|||
services:
|
||||
imap-json-fetcher:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
image: git.nixc.us/colin/imap-json-fetcher:staging
|
|
@ -1,21 +0,0 @@
|
|||
{
|
||||
"body": "test7\r\n",
|
||||
"date": "2024-05-04T12:43:34Z",
|
||||
"from": [
|
||||
{
|
||||
"PersonalName": "",
|
||||
"AtDomainList": "",
|
||||
"MailboxName": "imapfetcher",
|
||||
"HostName": "nixc.us"
|
||||
}
|
||||
],
|
||||
"subject": "test7",
|
||||
"to": [
|
||||
{
|
||||
"PersonalName": "",
|
||||
"AtDomainList": "",
|
||||
"MailboxName": "imapfetcher",
|
||||
"HostName": "nixc.us"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -1,21 +0,0 @@
|
|||
{
|
||||
"body": "test8\r\n",
|
||||
"date": "2024-05-04T12:43:53Z",
|
||||
"from": [
|
||||
{
|
||||
"PersonalName": "",
|
||||
"AtDomainList": "",
|
||||
"MailboxName": "imapfetcher",
|
||||
"HostName": "nixc.us"
|
||||
}
|
||||
],
|
||||
"subject": "test8",
|
||||
"to": [
|
||||
{
|
||||
"PersonalName": "",
|
||||
"AtDomainList": "",
|
||||
"MailboxName": "imapfetcher",
|
||||
"HostName": "nixc.us"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -1,21 +0,0 @@
|
|||
{
|
||||
"body": "test9\r\n",
|
||||
"date": "2024-05-04T13:15:07Z",
|
||||
"from": [
|
||||
{
|
||||
"PersonalName": "",
|
||||
"AtDomainList": "",
|
||||
"MailboxName": "imapfetcher",
|
||||
"HostName": "nixc.us"
|
||||
}
|
||||
],
|
||||
"subject": "test9",
|
||||
"to": [
|
||||
{
|
||||
"PersonalName": "",
|
||||
"AtDomainList": "",
|
||||
"MailboxName": "imapfetcher",
|
||||
"HostName": "nixc.us"
|
||||
}
|
||||
]
|
||||
}
|
Loading…
Reference in New Issue