diff --git a/.github/workflows/integration-blog.yml b/.github/workflows/integration-blog.yml index b356250..e8608ef 100644 --- a/.github/workflows/integration-blog.yml +++ b/.github/workflows/integration-blog.yml @@ -47,7 +47,7 @@ jobs: - name: Build container run: | - bash services/tests/image/test-docker.sh + bash test/image/test-docker.sh - name: Test Blog services working-directory: services/test/integration diff --git a/test/image/.dockerignore b/test/image/.dockerignore new file mode 100644 index 0000000..f1618a6 --- /dev/null +++ b/test/image/.dockerignore @@ -0,0 +1,4 @@ +**/Dockerfile +**/*.md +**/*.git +**/*.dockerignore \ No newline at end of file diff --git a/test/image/Dockerfile b/test/image/Dockerfile new file mode 100644 index 0000000..ad91e5c --- /dev/null +++ b/test/image/Dockerfile @@ -0,0 +1,32 @@ +FROM alpine:latest +RUN apk add make git go gcc libtool musl-dev curl bash + +# Configure Go +ENV GOROOT /usr/lib/go +ENV GOPATH /go +ENV PATH /go/bin:$PATH + +RUN mkdir -p ${GOPATH}/src ${GOPATH}/bin + +RUN apk add ca-certificates && \ + rm -rf /var/cache/apk/* /tmp/* && \ + [ ! -e /etc/nsswitch.conf ] && echo 'hosts: files dns' > /etc/nsswitch.conf + +RUN apk add --update ca-certificates openssl tar && \ + wget https://github.com/coreos/etcd/releases/download/v3.4.7/etcd-v3.4.7-linux-amd64.tar.gz && \ + tar xzvf etcd-v3.4.7-linux-amd64.tar.gz && \ + mv etcd-v3.4.7-linux-amd64/etcd* /bin/ && \ + apk del --purge tar openssl && \ + rm -Rf etcd-v3.4.7-linux-amd64* /var/cache/apk/* +VOLUME /data +EXPOSE 2379 2380 4001 7001 +ADD services/tests/image/run-etcd.sh /bin/run.sh + +# Speeding up tests by predownloading and building dependencies for services used. +RUN mkdir services +COPY services/go.* services/ +RUN cd services && go mod download +COPY services/ services +RUN bash -c 'for d in $(find services -name "main.go" | xargs -n 1 dirname); do pushd $d && go install && popd; done' +COPY ./micro/micro /microserver +ENTRYPOINT ["sh", "/bin/run.sh"] diff --git a/test/image/run-etcd.sh b/test/image/run-etcd.sh new file mode 100644 index 0000000..88aa675 --- /dev/null +++ b/test/image/run-etcd.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +ETCD_CMD="/bin/etcd -data-dir=/data" +echo -e "Running '$ETCD_CMD'\nBEGIN ETCD OUTPUT\n" + +exec $ETCD_CMD & +sleep 4 +/microserver $* diff --git a/test/image/test-docker.sh b/test/image/test-docker.sh new file mode 100755 index 0000000..ecb83a9 --- /dev/null +++ b/test/image/test-docker.sh @@ -0,0 +1,5 @@ +cp services/tests/image/.dockerignore . +pushd micro +GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build +popd +DOCKER_BUILDKIT=1 docker build -t micro -f services/tests/image/Dockerfile .