|
10 | 10 |
|
11 | 11 | # Docker image tagging:
|
12 | 12 | HUB_USER?=${USER}
|
| 13 | + |
| 14 | +# When you create your secret use the DockerHub in the name and this will find it |
| 15 | +HUB_PULL_SECRET?=$(shell docker secret list | grep arn | grep DockerHub | cut -f1 -d' ') |
13 | 16 | REPO?=$(shell basename ${PWD})
|
14 | 17 | TAG?=${GIT_TAG}
|
15 | 18 | DEV_IMAGE?=${REPO}:latest
|
|
28 | 31 | # Run the unit tests.
|
29 | 32 | .PHONY: build-test unit-test test
|
30 | 33 | unit-test:
|
31 |
| - @docker build --progress plain --target test ./app |
| 34 | + @docker --context default build --progress plain --target test ./app |
32 | 35 |
|
33 | 36 | test: unit-test
|
34 | 37 |
|
35 | 38 | # Build a production image for the application.
|
36 | 39 | .PHONY: build
|
37 | 40 | build:
|
38 |
| - @docker build --target prod --tag ${PROD_IMAGE} ./app |
| 41 | + @docker --context default build --target prod --tag ${PROD_IMAGE} ./app |
39 | 42 |
|
40 | 43 | # Push the production image to a registry.
|
41 | 44 | .PHONY: push
|
42 | 45 | push: build
|
43 |
| - @docker push ${PROD_IMAGE} |
| 46 | + @docker --context default push ${PROD_IMAGE} |
44 | 47 |
|
45 | 48 | # Run the production image either via compose or run
|
46 | 49 | .PHONY: deploy run
|
47 |
| -deploy: build |
48 |
| - @PROD_IMAGE=${PROD_IMAGE} docker-compose up -d |
| 50 | +deploy: build push check-env |
| 51 | + HUB_PULL_SECRET=${HUB_PULL_SECRET} PROD_IMAGE=${PROD_IMAGE} docker compose up |
49 | 52 |
|
50 | 53 | run: build
|
51 |
| - @docker run -d -p 5000:5000 ${PROD_IMAGE} |
| 54 | + @docker --context default run -d -p 5000:5000 ${PROD_IMAGE} |
52 | 55 |
|
53 | 56 | # Remove the dev container, dev image, test image, and clear the builder cache.
|
54 | 57 | .PHONY: clean
|
55 | 58 | clean:
|
56 | 59 | @docker-compose -f docker-compose.dev.yml down
|
57 | 60 | @docker rmi ${DEV_IMAGE} || true
|
58 | 61 | @docker builder prune --force --filter type=exec.cachemount --filter=unused-for=24h
|
| 62 | + |
| 63 | +.PHONY: check-env |
| 64 | +check-env: |
| 65 | +ifndef HUB_PULL_SECRET |
| 66 | + $(error HUB_PULL_SECRET is undefined. Use docker ecs secret ls to find the ARN) |
| 67 | +endif |
0 commit comments