-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·35 lines (29 loc) · 1.22 KB
/
build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/env bash
# Author: Ryan Tierney
# Date: 2022-12-22
# Purpose: Compile the Go source code using docker for any debian OS
# Notes: Update the operating_system variable in this script to compile on the debian OS of your choice
# The compiled binary will be saved in the projects working directory - save location is displayed at the end
# The docker image will not be removed. This can be used for local testing to simulate running the binary in the target OS.
set -euo pipefail
bin_name="promflow"
operating_system="debian:stretch"
pid="$$"
work_dir="$PWD"
image_name="${bin_name}"
container_name="${bin_name}_container_${pid}"
cleanup () {
set +e
rm "${bin_name}.tar"
rm -rf go/
docker rm "${container_name}" &> /dev/null
}
trap cleanup EXIT
sed -i "s/FROM .*/FROM ${operating_system}/" Dockerfile
docker build . -t ${image_name}
docker run --entrypoint="true" --name="${container_name}" "${image_name}"
docker export --output="${bin_name}.tar" "${container_name}"
tar --extract --file="${bin_name}.tar" "go/src/myproject/myproject"
mv go/src/myproject/myproject "${bin_name}"
echo "Binary built and saved to: ${work_dir}/${bin_name}"
echo "To test locally on ${operating_system}: docker run --net=host ${image_name} -h"