diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..4641339 --- /dev/null +++ b/Dockerfile @@ -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"] diff --git a/Dockerfile.production b/Dockerfile.production new file mode 100644 index 0000000..7f15455 --- /dev/null +++ b/Dockerfile.production @@ -0,0 +1 @@ +FROM git.nixc.us/colin/imap-json-fetcher:staging \ No newline at end of file diff --git a/build.sh b/build.sh index 64446cd..39b1b59 100755 --- a/build.sh +++ b/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." - diff --git a/docker-compose.production.yml b/docker-compose.production.yml new file mode 100644 index 0000000..fdc4bdf --- /dev/null +++ b/docker-compose.production.yml @@ -0,0 +1,6 @@ +services: + imap-json-fetcher: + build: + context: . + dockerfile: Dockerfile.production + image: git.nixc.us/colin/imap-json-fetcher:production \ No newline at end of file diff --git a/docker-compose.staging.yml b/docker-compose.staging.yml new file mode 100644 index 0000000..803b27d --- /dev/null +++ b/docker-compose.staging.yml @@ -0,0 +1,6 @@ +services: + imap-json-fetcher: + build: + context: . + dockerfile: Dockerfile + image: git.nixc.us/colin/imap-json-fetcher:staging \ No newline at end of file diff --git a/email-20240504-084413-0.json b/email-20240504-084413-0.json deleted file mode 100644 index ad53da7..0000000 --- a/email-20240504-084413-0.json +++ /dev/null @@ -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" - } - ] -} \ No newline at end of file diff --git a/email-20240504-084413-1.json b/email-20240504-084413-1.json deleted file mode 100644 index e9e45e5..0000000 --- a/email-20240504-084413-1.json +++ /dev/null @@ -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" - } - ] -} \ No newline at end of file diff --git a/email-20240504-091515-0.json b/email-20240504-091515-0.json deleted file mode 100644 index 7c204c0..0000000 --- a/email-20240504-091515-0.json +++ /dev/null @@ -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" - } - ] -} \ No newline at end of file