So I've configured my .travis.yml to build and test my ASP.NET Core project, but now I've to configure it to run in docker. So far so good, I've the Dockerfile for the build, but then I started to figure:
Should I run the testing inside the Docker Container or outside? Or Does it even matter?
If I should do it inside how could this be achieved? since dotnet test doesn't have **/*/ support and my container doesn't run my bash script.
UPDATE:
Or should I build and test outside and later create the dockerimage?
The Dockerfile is:
FROM microsoft/dotnet:latest
ARG source=.
WORKDIR /usr/src/project
COPY $source .
RUN dotnet restore
EXPOSE 5000
CMD dotnet build **/*/project.json
And the .sh is:
#!/bin/bash
cd test/
for D in `find ./ -maxdepth 1 -type d`
do
if [ -a ./project.json ]
then
( cd ${D}; dotnet test;)
fi
done
Any suggestions are greatly appreciated.
So I decided that the docker build and publish should only be done if the build and test succeeded
.travis.yml
language: csharp
sudo: required
solution: Solution.sln
mono: none
dotnet: 1.0.0-preview2-1-003177
services:
- docker
install:
- npm install -g bower
- npm install -g gulp
before_script:
- chmod a+x ./scripts/test.sh
script:
- dotnet restore && dotnet build **/*/project.json
- ./scripts/test.sh --quite verify
- if [ "$TRAVIS_BRANCH" == "master" ] ; then
dotnet publish --no-build src/Main -o publish/ ;
docker build -t project . ;
fi
after_success:
- if [ "$TRAVIS_BRANCH" == "master" ] ; then
/* Push to docker repo */
fi
Related
I really can't understand why on my machine via SSH I can execute npm commands and in deploy pipeline is not work? Wtf
Starting deploy
Already up to date.
v16.7.0
7.20.3
Deploy end
Result in CircleCI
Starting deploy
Already up to date.
deploy.sh: line 6: node: command not found
deploy.sh: line 7: npm: command not found
Deploy end
version: 2.1
# Define the jobs we want to run for this project
jobs:
pull-and-build:
docker:
- image: arvindr226/alpine-ssh
steps:
- checkout
- run: ssh -o StrictHostKeyChecking=no ubuntu#xx.xx.xx.xx "cd ~/apps/clm/core; sudo bash deploy.sh"
# Orchestrate our job run sequence
workflows:
version: 2
build-project:
jobs:
- pull-and-build:
filters:
branches:
only:
- Desenvolvimento
My bash script
#!/bin/bash
echo "Starting deploy"
cd ~/apps/clm/core
git pull
node -v
npm -v
echo "Deploy end"
Thanks a lot to anyone who helps.
I really don't understand what's going on I've tried looking for everything...
The problem was in the PATH!
ssh -o StrictHostKeyChecking=no xxx#xx.xxx.xx.xx "source ~/.nvm/nvm.sh; cd ~/apps/xxx/xxx; git pull; npm install; pm2 restart core client"
Im quite new to bitbucket pipeline and i was looking into how to run my jmeter script in the pipeline without using Jenkins or bamboo. I have created a bitbucket-pipelines.yml file and got an issue "jmeter: command not found"
here is the script that i created.
pipelines:
branches:
master:
- step:
name: Jmeter
script:
- jmeter run Observability_Test.jmx
If jmeter command is not found you need to install JMeter prior to trying to launch the test.
Example configuration:
pipelines:
default:
- step:
script:
- apt-get update && apt-get install --no-install-recommends -y openjdk-11-jre wget
- cd /opt && wget https://archive.apache.org/dist/jmeter/binaries/apache-jmeter-5.4.3.tgz && tar xf apache-jmeter-5.4.3.tgz
- cd apache-jmeter-5.4.3/bin && ./jmeter -n -t /path/to/Observability_Test.jmx
- cd apache-jmeter-5.4.3/bin && ./jmeter -n -t /path/to/Observability_Test.jmx
More information: Tips for scripting tasks with Bitbucket Pipelines
I have the following .gitlab-ci.yml...
stages:
- test
- build
- art
image: golang:1.9.2
variables:
BIN_NAME: example
ARTIFACTS_DIR: artifacts
GO_PROJECT: example
GOPATH: /go
before_script:
- mkdir -p ${GOPATH}/src/${GO_PROJECT}
- mkdir -p ${CI_PROJECT_DIR}/${ARTIFACTS_DIR}
- go get -u github.com/golang/dep/cmd/dep
- cp -r ${CI_PROJECT_DIR}/* ${GOPATH}/src/${GO_PROJECT}/
- cd ${GOPATH}/src/${GO_PROJECT}
test:
stage: test
script:
# Run all tests
go test -run ''
build:
stage: build
script:
# Compile and name the binary as `hello`
- go build -o hello
- pwd
- ls -l hello
# Execute the binary
- ./hello
# Move to gitlab build directory
- mv ./hello ${CI_PROJECT_DIR}
artifacts:
paths:
- ./hello
This works great for linux but i now need to do the same so that it builds a windows executable.
I then plan to run a scheduled script to download the artifacts.
The other option is I run a virtual linux server on the windows server and use that to run my go binarys.
I know i need to change the image to windows but can't see to find an appropriate one online (one that is configured for golang).
Or is it possible to have this docker image build a windows exe?
This is not a gitlab question, but a go question.
Since Go version 1.5 cross-compiling has become very easy.
GOOS=windows GOARCH=386 go build -o hello.exe hello.go
You can now run hello.exe on a Windows machine
I have this Golang based Dockerfile:
FROM golang:latest
RUN mkdir -p /app
WORKDIR /app
COPY bin/huru .
CMD ./huru
I checked and the huru binary file is in the working dir. I get this error:
/bin/sh: 1: ./huru: Exec format error
anyone know what that is about? "docker build" succeeds, but "docker run" fails with that error.
The "Exec format error" was simply because I was copying the binary file built on OSX/MacOS into the Docker image and trying to run that binary file in the Linux container. That don't work.
Here is the Dockerfile that worked for me:
FROM golang:latest
RUN mkdir -p /app
WORKDIR /app
COPY . .
ENV GOPATH /app
RUN go install huru
ENTRYPOINT /app/bin/huru
and my project structure like so on my host fs:
$GOPATH/
src/
huru/
.dockerignore
Dockerfile
I run:
docker build -t foo .
docker run foo
my .dockerignore file contains:
.vscode
bin
pkg
If you want to run the docker image on Macos then just specifying the target OS is sufficient:
Assuming there is a src and bin folder, execute in the src folder:
env GOOS=linux go build -o ../bin
(this works with m1, uses the arm64 architecture)
BTW
I would not use latest, I see that there is a docker image based on 1.20 which is not yet officially released at time of writing.
You could build your application (huru) for the target architecture in MacOS and then copy it into the docker image. To build for the target architecture you have to use command in the following format:
env GOOS=linux GOARCH=amd64 go build -o application main.go
This has the added advantage of having a clean dockerfile and smaller image.
Hi I am pretty new to go, and this is my first time working with docker to package an app into a container. I am working on a linux VM where the app is located under dir: /home/core/app/app-name In the dir app-name there is the main.go program and the Dockerfile. The Dockerfile contains this:
FROM golang:latest
RUN mkdir /app
ADD . /home/core/app/app-name
WORKDIR /app/app-name
RUN go build -o main .
CMD ["/app/main"]
EXPOSE 8080
I have tried running from dir /home/core/app/app-name:
docker build -t app-image .
But I got this error:
can't load package: package .: no buildable Go source files in /app/stars-app
The command '/bin/sh -c go build -o main .' returned a non-zero code: 1
What am I doing wrong?
Edit:
I got was able to build the image on my windows machine with the Dockfile:
FROM golang:latest
Add . /app/app-name
EXPOSE 8080
CMD ["/app/app-name/main"]
And by running:
docker build -t star-image .
I can see the image when I run "docker images", but when I try to run it using:
docker run -p 3000:8080 --name goapp --rm app-name
I get this error:
docker: Error response from daemon: Container command '/app/app-name/main' not found or does not exist..
This might work for you...
The GOPATH for the image is set to /go
install your source(s) under /go/src
given the gopath is set and sources are within the GOPATH
setting the working directory to /app
execute the build and the output should be present in the working
directory
Dockerfile
FROM golang:latest
ADD ./app /go/src/app
RUN mkdir /app
WORKDIR /app
RUN go build -o main app/app-name
CMD ["/app/main"]
EXPOSE 8080
app/app-name/main.go
package main
import "fmt"
func main() {
fmt.Printf("hello, world\n")
}
docker build -t app-image .
docker run app-image
output
hello, world
I had problems with this too but somehow based on this guide, this worked for me.
# ...AS builder ...
FROM golang:1.14
WORKDIR /go/src/app
# In your case, ./main.go or just .
COPY ./server.go .
COPY --from=builder ./app/build .
RUN go get -d -v ./...
RUN go install -v ./...
CMD ["app"]