I have two jobs build_binary
and build deb
and I want to combine both of them. But the issue is they both use different images
. Former one uses golang:latest
and later one uses ubuntu:20.04
as shown:
gitlab-ci.yml
build_binary:
stage: build
image: golang:latest
rules:
- if: '$CI_COMMIT_TAG'
# tags:
# - docker-executor
artifacts:
untracked: true
script:
- echo "Some script"
build deb:
stage: deb-build
rules:
- if: '$CI_COMMIT_TAG'
# tags:
# - docker-executor
image: ubuntu:20.04
dependencies:
- build_binary
script:
- echo "Some script 2"
artifacts:
untracked: true
I have tried in these two ways but it didn’t work.
build_binary:
stage: build
image: golang:latest ubuntu:20.04
and
build_binary:
stage: build
image: [golang:latest,ubuntu:20.04]
Any pointers would be very helpful.
2
Answers
Using the image and services keywords in your.gitlab-ci.yml file, you may define a GitLab CI/CD job that uses multiple Docker images.
For example, you could use the following configuration to specify a job that uses both a Golang image and an Ubuntu image:
It’s not about
gitlab-ci
– for first hand you should understand what isimages
, what containers (docker) are in it’s nature.You cannot magically get
mixed image
that will be magicallyubuntu:20.04+golang:latest
. It’s just impossible to make it fromgitlab-ci
file.But you can create
your own IMAGE
.You can take Dockerfile for ubuntu:20.04, at dockerhub https://hub.docker.com/_/ubuntu
Then you can add commands to it to install golang inside this operation system `
After this you open golang:latest Dockerfile and copy it’s installation process to ubuntu Dockerfile with required modifications.
Then you do
docker build -t my-super-ubuntu-and-golang
– see manualThen you check it –
docker run
and check that it’s normal ubuntu withgolang
If all success you can push it to your own account to dockerhub and in gitlab-ci:
not mean that
rabbitmq will be started on alpine
– both will started – image of alpine and image of rabbitmq with local HOST namerabbitmq
, and your alpine could connect totcp://rabbitmq:5672
and use it. It’s another approach.P.S.
For example you can look at https://hub.docker.com/r/partlab/ubuntu-golang
I think it’s not image you really want but you can see how to make mixed ubuntu-golang image