|
| 1 | +.PHONY: image copy-app latest latest-tag test deploy-local local login-deploy |
| 2 | + |
| 3 | +-include .env |
| 4 | + |
| 5 | +branch ?= master |
| 6 | +NAME_IMAGE ?= "$(CI_REGISTRY_IMAGE)" |
| 7 | +TAG_IMAGE := branch-$(subst /,-,$(branch)) |
| 8 | + |
| 9 | +# We use :latest so we can use somewhere else, but it's the same as branch-master the other one is for CI |
| 10 | +ifeq ($(branch), latest) |
| 11 | + TAG_IMAGE=latest |
| 12 | +endif |
| 13 | + |
| 14 | + |
| 15 | +## Make remote image form a branch make image branch=<branchName> (master default) |
| 16 | +IMAGE_URL ?= $(CI_REGISTRY)/ubuntu:latest |
| 17 | +ifndef CI_REGISTRY |
| 18 | + IMAGE_URL = 'ubuntu:latest' |
| 19 | +endif |
| 20 | + |
| 21 | +## Copy the current app and remove some items we don't need inside the image |
| 22 | +# - .git -> huge and doesn't provide anything relevant |
| 23 | +# - .env -> it's private |
| 24 | +# - __SOURCE_APP -> if it exists, it should not but it's better to filter it out |
| 25 | +copy-app: |
| 26 | + @ cd .. |
| 27 | + @ rm -rf __SOURCE_APP || true |
| 28 | + @ rsync \ |
| 29 | + -avz \ |
| 30 | + --exclude .git \ |
| 31 | + --exclude .env \ |
| 32 | + --exclude __SOURCE_APP \ |
| 33 | + . __SOURCE_APP |
| 34 | + @ cd - > /dev/null |
| 35 | + |
| 36 | +requirements.txt: |
| 37 | + @ touch requirements.txt |
| 38 | + |
| 39 | +# Tag the image branch-master as latest |
| 40 | +latest: |
| 41 | + docker pull $(NAME_IMAGE):branch-master |
| 42 | + docker tag $(NAME_IMAGE):branch-master $(NAME_IMAGE):latest |
| 43 | + docker push $(NAME_IMAGE):latest |
| 44 | + |
| 45 | +## Build image on local -> name nm-core:latest |
| 46 | +local: requirements.txt copy-app |
| 47 | + @ docker build -t "$(NAME_IMAGE)" . |
| 48 | + @ rm -rf __SOURCE_APP || true |
| 49 | +local: NAME_IMAGE = proton-python-client:latest |
| 50 | + |
| 51 | + |
| 52 | +# Build an image from your computer and push it to our repository |
| 53 | +deploy-local: login-deploy build tag push |
| 54 | + |
| 55 | +# If you want to deploy an image to our registry you will need to set these variables inside .env |
| 56 | +login-deploy: |
| 57 | + docker login -u "$(CI_DEPLOY_USER)" -p "$(CI_JOB_TOKEN)" "$(CI_REGISTRY)" |
| 58 | + |
| 59 | +######### Not linked to the image ############### |
| 60 | + |
| 61 | +## Run tests against the latest version of the image from your code |
| 62 | +test: local |
| 63 | + # Keep -it because with colors it's better |
| 64 | + @ docker run \ |
| 65 | + --rm \ |
| 66 | + -it \ |
| 67 | + --privileged \ |
| 68 | + --volume $(PWD)/.env:/home/user/proton-python-client.env \ |
| 69 | + proton-python-client:latest \ |
| 70 | + python3 -m pytest |
0 commit comments