feat: Add dependency phase for easier caching
This commit is contained in:
		
							parent
							
								
									c6c1cb1afe
								
							
						
					
					
						commit
						ae7803a6c3
					
				
					 1 changed files with 34 additions and 11 deletions
				
			
		| 
						 | 
					@ -1,4 +1,5 @@
 | 
				
			||||||
stages:
 | 
					stages:
 | 
				
			||||||
 | 
					  - dependencies
 | 
				
			||||||
  - test
 | 
					  - test
 | 
				
			||||||
  - deploy_tags
 | 
					  - deploy_tags
 | 
				
			||||||
  - deploy
 | 
					  - deploy
 | 
				
			||||||
| 
						 | 
					@ -12,9 +13,37 @@ variables:
 | 
				
			||||||
  DOCKER_HOST: tcp://docker:2376
 | 
					  DOCKER_HOST: tcp://docker:2376
 | 
				
			||||||
  GIT_STRATEGY: fetch
 | 
					  GIT_STRATEGY: fetch
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					fetch_application_dependencies:
 | 
				
			||||||
 | 
					  stage: dependencies
 | 
				
			||||||
 | 
					  image: "elixir:1.10"
 | 
				
			||||||
 | 
					  cache:
 | 
				
			||||||
 | 
					    key:
 | 
				
			||||||
 | 
					      files:
 | 
				
			||||||
 | 
					        - mix.lock
 | 
				
			||||||
 | 
					    paths:
 | 
				
			||||||
 | 
					      - _build/
 | 
				
			||||||
 | 
					      - deps/
 | 
				
			||||||
 | 
					  script:
 | 
				
			||||||
 | 
					    - mix deps.get
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					fetch_asset_dependencies:
 | 
				
			||||||
 | 
					  stage: dependencies
 | 
				
			||||||
 | 
					  image: "node:15.0"
 | 
				
			||||||
 | 
					  only:
 | 
				
			||||||
 | 
					    - master
 | 
				
			||||||
 | 
					  cache:
 | 
				
			||||||
 | 
					    key:
 | 
				
			||||||
 | 
					      files:
 | 
				
			||||||
 | 
					        - apps/app/assets/package-lock.json
 | 
				
			||||||
 | 
					    paths:
 | 
				
			||||||
 | 
					      - apps/app/assets/node_modules/
 | 
				
			||||||
 | 
					  script:
 | 
				
			||||||
 | 
					    - cd apps/app/assets/ && npm install
 | 
				
			||||||
 | 
					
 | 
				
			||||||
test:
 | 
					test:
 | 
				
			||||||
  stage: test
 | 
					  stage: test
 | 
				
			||||||
  needs: []
 | 
					  needs:
 | 
				
			||||||
 | 
					    - fetch_application_dependencies
 | 
				
			||||||
  image: "elixir:1.10"
 | 
					  image: "elixir:1.10"
 | 
				
			||||||
  services:
 | 
					  services:
 | 
				
			||||||
  - name: postgres:12
 | 
					  - name: postgres:12
 | 
				
			||||||
| 
						 | 
					@ -29,26 +58,20 @@ test:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
build_image_for_commit:
 | 
					build_image_for_commit:
 | 
				
			||||||
  stage: test
 | 
					  stage: test
 | 
				
			||||||
  needs: []
 | 
					  needs:
 | 
				
			||||||
 | 
					    - fetch_asset_dependencies
 | 
				
			||||||
 | 
					    - fetch_application_dependencies
 | 
				
			||||||
  image: "docker:19.03.12"
 | 
					  image: "docker:19.03.12"
 | 
				
			||||||
  only:
 | 
					  only:
 | 
				
			||||||
    - master
 | 
					    - master
 | 
				
			||||||
  services:
 | 
					  services:
 | 
				
			||||||
    - name: docker:19.03.12-dind
 | 
					    - name: docker:19.03.12-dind
 | 
				
			||||||
  cache:
 | 
					 | 
				
			||||||
    key:
 | 
					 | 
				
			||||||
      files:
 | 
					 | 
				
			||||||
        - mix.lock
 | 
					 | 
				
			||||||
        - apps/app/assets/package-lock.json
 | 
					 | 
				
			||||||
    paths:
 | 
					 | 
				
			||||||
      - _build/
 | 
					 | 
				
			||||||
      - deps/
 | 
					 | 
				
			||||||
      - apps/app/assets/node_modules/
 | 
					 | 
				
			||||||
  script:
 | 
					  script:
 | 
				
			||||||
    - docker login "https://${CI_REGISTRY}" -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD
 | 
					    - docker login "https://${CI_REGISTRY}" -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD
 | 
				
			||||||
    - docker pull $CI_REGISTRY_IMAGE:latest || true
 | 
					    - docker pull $CI_REGISTRY_IMAGE:latest || true
 | 
				
			||||||
    - docker build --cache-from $CI_REGISTRY_IMAGE:latest -t $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA .
 | 
					    - docker build --cache-from $CI_REGISTRY_IMAGE:latest -t $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA .
 | 
				
			||||||
    - docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
 | 
					    - docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
 | 
				
			||||||
 | 
					    - docker cp $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
deploy_to_tags:
 | 
					deploy_to_tags:
 | 
				
			||||||
  stage: deploy_tags
 | 
					  stage: deploy_tags
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue