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

138
Vistas
What is wrong with this Makefile? Needs to be run twice in order to work

Running make once yields an error suggesting that $(shell docker run -d $(IMAGE)) is not working as intended.

However running a second time works like a charm.

Seems like make build-image build-api causes the target build-api to not wait for the completion of build-image? Should i introduce a delayed execution? (the infamous sleep :D)

$ cat Makefile
.PHONY: build

IMAGE := tensorflow-serving-grpc

build: build-image build-api

clean:
        -docker rmi -f $(IMAGE)

build-image:
        docker build -t $(IMAGE) .

build-api: CONTAINER_ID:=$(shell docker run -d $(IMAGE))
build-api:
        docker wait $(CONTAINER_ID)
        docker cp $(CONTAINER_ID):/usr/src/vendor ./
        docker rm -f $(CONTAINER_ID)
over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

If it doesn't wait then it's because you allowed parallel execution with -jN option run it from $(shell...). Using $(shell ...) should be avoided unless you know what you do.

You should also prevent parallel execution of build-image and build-api by declaring a prerequisite.

.ONESHELL:
build-api: build-image
    set -e
    CONTAINER_ID=`docker run -d $(IMAGE)`
    docker wait $$(CONTAINER_ID)
    docker cp $$(CONTAINER_ID):/usr/src/vendor ./
    docker rm -f $$(CONTAINER_ID)
over 4 years ago · Santiago Trujillo Denunciar

0

You have a target specific variable with a side effect, and you're making the incorrect assumption that the variable won't be expanded until the rule is run. I would switch to using a bash variable, and concatenating the recipe to be run in a single shell as follows:

build-api: build-image
    CONTAINER_ID=$$(docker run -d $(IMAGE)); \
    docker wait $${CONTAINER_ID}; \
    docker cp $${CONTAINER_ID}:/usr/src/vendor ./; \
    docker rm -f $${CONTAINER_ID};

Another option is to create a target which creates the container id, and stores it in a file. Make build-api dependent on this new target, and then in build-api, have each recipe line read the value from the file.

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