Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

411
Vistas
How do I have multiple docker images available in one stage Git lab CI

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

The issue is my program is dependant on both Go and Mysql...

I am aware i can have a different docker image for each stage but my test stage needs both

go test & MySql

What I have looked into:

I have learn ho to create my own docker image based using docker commit and also how to use a docker file to build and image up.

However I have hear there are way to link docker containers together using docker compose, and this seems like a better method...

I have no idea how to go about this in GitLab, I know I need a compose.yml file but not sure where to put it, whats need to go in it, does it create an image that I then link to from my .gitlab-ci.yml file?

Perhaps this is over kill and there is a simpler way?

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

I understand your tests need a MySQL server in order to work and that you are using some kind of MySQL client or driver in your Go tests.

You can use a Gitlab CI service which will be made available during your test job. GitlabCI will run a MySQL container beside your Go container which will be reachable via it's name from the Go container. For example:

test:   
  stage: test
  services: 
  - mysql:5.7
  variables:
    # Configure mysql environment variables (https://hub.docker.com/_/mysql/)
    MYSQL_DATABASE: mydb
    MYSQL_ROOT_PASSWORD: password
  script:
    # Run all tests
    go test -run ''

Will start a MySQL container and it will be reachable from the Go container via hostname mysql. Note you'll need to define variables for MySQL startup as per the Environment variables section of image documentation (such as Root password or database to create)

You can also define the service globally (will be made available for each job in your build) and use an alias so the MySQL server will be reachable from another hostname.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda