feat: Speed up build through DAG improvements

This commit is contained in:
Robert Prehn 2021-01-13 15:43:04 -06:00
parent 900f5f3bce
commit 894580a1bd
4 changed files with 38 additions and 20 deletions

3
.gitignore vendored
View file

@ -37,3 +37,6 @@ node_modules
Brewfile.lock.json
config/*.secret.exs
# Temporary CI build file
build.env

View file

@ -23,46 +23,50 @@ test:
- name: postgres:12
script: script/cibuild
deploy_to_tags:
stage: deploy
needs: ['test']
image: "node:15.0"
only:
- master
except:
- tags
script:
- npm install
- npx semantic-release
build_image_for_commit:
stage: test
needs: []
image: "docker:19.03.12"
services:
- name: docker:19.03.12-dind
only:
- tags
script:
- docker login "https://${CI_REGISTRY}" -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD
- docker pull $CI_REGISTRY_IMAGE:latest || true
- docker build --cache-from $CI_REGISTRY_IMAGE:latest -t $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA .
- docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
deploy_to_tags:
stage: deploy
needs: ['test']
image: "node:15.0"
only:
- master
script:
- npm install
- npx semantic-release
- script/generate-build-version
artifacts:
reports:
dotenv: build.env
deploy_commit_image_to_tag:
stage: deploy
needs: ['test', 'build_image_for_commit']
needs:
- build_image_for_commit
- job: deploy_to_tags
artifacts: true
only:
- master
image: "docker:19.03.12"
services:
- name: docker:19.03.12-dind
only:
- tags
script:
- echo "BUILD_VERSION is ${BUILD_VERSION}"
- docker login "https://${CI_REGISTRY}" -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD
# Run the docker pull, but retry if it doesn't work at first because layers may be
# still be loading to storage
- for i in 1 2 3 4 5; do docker pull $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA && break || sleep 15; done
- docker tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA $CI_REGISTRY_IMAGE:$CI_COMMIT_TAG
- docker tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA $CI_REGISTRY_IMAGE:$BUILD_VERSION
- docker tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA $CI_REGISTRY_IMAGE:latest
- docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_TAG
- docker push $CI_REGISTRY_IMAGE:$BUILD_VERSION
- docker push $CI_REGISTRY_IMAGE:latest

View file

@ -41,7 +41,6 @@
[
"@semantic-release/git",
{
"message": "chore(release): ${nextRelease.version}\n\n${nextRelease.notes}",
"assets": [
"package.json",
"infrastructure/kube.yml"

12
script/generate-build-version Executable file
View file

@ -0,0 +1,12 @@
#!/usr/bin/env node
const fs = require("fs");
const doT = require("dot");
var packageText = fs.readFileSync("package.json", {encoding: "utf8"});
var packageConfig = JSON.parse(packageText);
const {version} = packageConfig;
const template = doT.template("BUILD_VERSION={{=it.version}}")
fs.writeFileSync("build.env", template({version}));