Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

410
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda