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
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"
I've been following a lot of tutorials on CI using Python but the tutorials seem to stop there and rarely take the next step to CD. I'm a sole developer as well.
I've setup a project on Github that runs locally on my PC and is not a web app. I've connected it to CircleCI for CI. Here is my config.yml file.
version: 2
jobs:
build:
docker:
- image: circleci/python:3.7
working_directory: ~/repo
steps:
# Step 1: obtain repo from GitHub
- checkout
- run:
name: install dependencies
command: |
sudo apt-get update
pip install -r requirements.txt
- run:
name: run tests
command: |
python -m pytest -v
Everything runs great and I get an email from CircleCI alerting me the build failed when I make a push to master on github and one the of the pytests fail.
So my question, is what is the next step here? I have a few thoughts but am not sure on any of them honestly.
Create separate test and prod versions of the code. Automate updating the prod version when the test version builds with no errors. However, not sure what tools to use for this.
Push to project to Dockerhub. This seems redundant to me though, because Docker would run the same pytests that CircleCI is running. I'm not sure how this would even help with CD at this point.
Could someone please provide some guidance on next steps here?
Currently you have only one job build, so you can add more jobs under the jobs section. So what you want to do here is:
add test
build prod version
Push to Dockerhub
Please use config 2.1 to enable the workflows.
version: 2.1
jobs:
build:
docker:
- image: circleci/python:3.7
working_directory: ~/repo
steps:
# Step 1: obtain repo from GitHub
- checkout
- run:
name: install dependencies
command: |
sudo apt-get update
pip install -r requirements.txt
- run:
name: run tests
command: |
python -m pytest -v
test:
docker:
- image: circleci/python:3.7
steps:
- checkout
- run: echo "do your test here"
build-prod:
docker:
- image: circleci/python:3.7
steps:
- checkout
- run: echo "build your app"
push-to-dockerhub:
docker:
- image: circleci/python:3.7
steps:
- checkout
- setup_remote_docker # this is necessary to use docker daemon
- run: echo "do docker login and docker push here"
workflows:
build-and-push:
jobs:
- build
- test
requires:
- build
- build-prod
requires:
- test
- push-to-dockerhub
requires:
- build-prod
Please make sure we're using requires to run the job only when the required job is finished successfully.
Well definitely I've not tested the config on my end, but it's like above config. You have more configuration documents here - so please take a look for it to make it perfectly work.
https://circleci.com/docs/2.0/configuration-reference/
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.
I have Go test file and it needs root privilege to run it (go test). How to set it in Travis ci?
Here is yml:
language: go
sudo: required
go:
- tip
notifications:
email:
on_success: change
on_failure: always
After git push, travis-ci build failing with default configure.
In travis you can use sudo so if you want to run your tests with root permission, change the script section:
script: sudo -E env "PATH=$PATH" go test ./...
Or if you are using a Makefile:
script: sudo -E env "PATH=$PATH" make
script:
- sudo env "PATH=$PATH" npm test
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