mirror of
https://github.com/TECHNOFAB11/dbmate.git
synced 2025-12-11 23:50:04 +01:00
Add cross compilation scripts
This commit is contained in:
parent
d4b34dd49f
commit
d318e68423
5 changed files with 85 additions and 34 deletions
26
.gitignore
vendored
26
.gitignore
vendored
|
|
@ -1,24 +1,2 @@
|
|||
# Compiled Object files, Static and Dynamic libs (Shared Objects)
|
||||
*.o
|
||||
*.a
|
||||
*.so
|
||||
|
||||
# Folders
|
||||
_obj
|
||||
_test
|
||||
|
||||
# Architecture specific extensions/prefixes
|
||||
*.[568vq]
|
||||
[568vq].out
|
||||
|
||||
*.cgo1.go
|
||||
*.cgo2.c
|
||||
_cgo_defun.c
|
||||
_cgo_gotypes.go
|
||||
_cgo_export.*
|
||||
|
||||
_testmain.go
|
||||
|
||||
*.exe
|
||||
*.test
|
||||
*.prof
|
||||
.DS_Store
|
||||
/dist
|
||||
|
|
|
|||
36
Dockerfile
36
Dockerfile
|
|
@ -1,19 +1,39 @@
|
|||
FROM alpine:edge
|
||||
FROM golang:1.5.1
|
||||
|
||||
ENV GOPATH /go
|
||||
ENV PATH /go/bin:$PATH
|
||||
ENV CGO_ENABLED 1
|
||||
|
||||
# install build dependencies
|
||||
RUN echo "http://dl-4.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories && \
|
||||
apk add -U --no-progress alpine-sdk go go-tools
|
||||
# i386 cross compilation
|
||||
RUN dpkg --add-architecture i386 && \
|
||||
apt-get update && \
|
||||
apt-get install -y libc6-dev-i386 && \
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# osx cross compilation
|
||||
# ref: https://github.com/karalabe/xgo/blob/master/docker/base/Dockerfile
|
||||
ENV OSX_SDK_FILE MacOSX10.9.sdk.tar.xz
|
||||
ENV OSX_SDK_SHA256 ac7ccfd8dee95d9811ce50cdc154c8ec7181c51652b5a434445475af62c4fedb
|
||||
RUN cd /opt && \
|
||||
git clone https://github.com/tpoechtrager/osxcross.git && \
|
||||
cd osxcross && \
|
||||
sed -i -e 's|-march=native||g' ./build_clang.sh ./wrapper/build.sh && \
|
||||
apt-get update && \
|
||||
./tools/get_dependencies.sh && \
|
||||
rm -rf /var/lib/apt/lists/* && \
|
||||
curl -fSL -o ./tarballs/$OSX_SDK_FILE \
|
||||
https://s3.amazonaws.com/andrew-osx-sdks/$OSX_SDK_FILE && \
|
||||
echo "$OSX_SDK_SHA256 ./tarballs/$OSX_SDK_FILE" | sha256sum -c - && \
|
||||
UNATTENDED=1 OSX_VERSION_MIN=10.6 ./build.sh
|
||||
ENV PATH /opt/osxcross/target/bin:$PATH
|
||||
|
||||
# development dependencies
|
||||
RUN go get \
|
||||
github.com/golang/lint/golint \
|
||||
github.com/kisielk/errcheck \
|
||||
golang.org/x/tools/cmd/vet
|
||||
|
||||
# copy source files
|
||||
COPY . /go/src/github.com/adrianmacneil/dbmate
|
||||
WORKDIR /go/src/github.com/adrianmacneil/dbmate
|
||||
COPY . $GOPATH/src/github.com/adrianmacneil/dbmate
|
||||
WORKDIR $GOPATH/src/github.com/adrianmacneil/dbmate
|
||||
|
||||
# build
|
||||
RUN go get -d -t -v
|
||||
|
|
|
|||
32
Dockerfile.build
Normal file
32
Dockerfile.build
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
# this container is used for compiling dbmate against multiple targets
|
||||
FROM golang:1.5.1
|
||||
|
||||
ENV CGO_ENABLED 1
|
||||
|
||||
# i386 cross compilation
|
||||
RUN dpkg --add-architecture i386 && \
|
||||
apt-get update && \
|
||||
apt-get install -y libc6-dev-i386 && \
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# osx cross compilation
|
||||
# ref: https://github.com/karalabe/xgo/blob/master/docker/base/Dockerfile
|
||||
ENV OSX_SDK_VERSION 10.9
|
||||
RUN cd /opt && \
|
||||
git clone https://github.com/tpoechtrager/osxcross.git && \
|
||||
cd osxcross && \
|
||||
sed -i -e 's|-march=native||g' ./build_clang.sh ./wrapper/build.sh && \
|
||||
apt-get update && \
|
||||
./tools/get_dependencies.sh && \
|
||||
rm -rf /var/lib/apt/lists/* && \
|
||||
curl -fSL -o ./tarballs/MacOSX${OSX_SDK_VERSION}.sdk.tar.xz \
|
||||
https://s3.amazonaws.com/andrew-osx-sdks/MacOSX${OSX_SDK_VERSION}.sdk.tar.xz && \
|
||||
UNATTENDED=1 OSX_VERSION_MIN=10.6 ./build.sh
|
||||
ENV PATH /opt/osxcross/target/bin:$PATH
|
||||
|
||||
# copy source files
|
||||
COPY . $GOPATH/src/github.com/adrianmacneil/dbmate
|
||||
WORKDIR $GOPATH/src/github.com/adrianmacneil/dbmate
|
||||
|
||||
# fetch dependencies
|
||||
RUN go get -d -t -v
|
||||
7
Makefile
7
Makefile
|
|
@ -1,8 +1,8 @@
|
|||
DOCKER := docker-compose run dbmate
|
||||
|
||||
all: build lint test
|
||||
all: container lint test build
|
||||
|
||||
build:
|
||||
container:
|
||||
docker-compose build
|
||||
|
||||
lint:
|
||||
|
|
@ -12,3 +12,6 @@ lint:
|
|||
|
||||
test:
|
||||
$(DOCKER) go test -v
|
||||
|
||||
build:
|
||||
docker-compose run dbmate ./build.sh
|
||||
|
|
|
|||
18
build.sh
Executable file
18
build.sh
Executable file
|
|
@ -0,0 +1,18 @@
|
|||
#!/bin/sh
|
||||
# this script is intended to run inside the docker container
|
||||
# e.g. docker-compose run dbmate ./build.sh
|
||||
|
||||
set -ex
|
||||
|
||||
BUILD_FLAGS="-ldflags -s"
|
||||
|
||||
rm -rf dist
|
||||
|
||||
GOOS=linux GOARCH=386 go build $BUILD_FLAGS \
|
||||
-o dist/dbmate-linux-i386
|
||||
GOOS=linux GOARCH=amd64 go build $BUILD_FLAGS \
|
||||
-o dist/dbmate-linux-amd64
|
||||
GOOS=darwin GOARCH=386 CC=o32-clang CXX=o32-clang++ go build $BUILD_FLAGS \
|
||||
-o dist/dbmate-osx-i386
|
||||
GOOS=darwin GOARCH=amd64 CC=o64-clang CXX=o64-clang++ go build $BUILD_FLAGS \
|
||||
-o dist/dbmate-osx-amd64
|
||||
Loading…
Add table
Add a link
Reference in a new issue