image: gitlab/dind before_script: # - docker info - export REV=$(git rev-list HEAD --count) - export BUILDDATE=$(date) - export BRANCH=$CI_COMMIT_REF_SLUG - export IMAGE=dr.dnix.de/$CI_PROJECT_NAME variables: VERSIONGO: version.go stages: - build - test - deploy build: stage: build script: - echo "Building image $IMAGE:$BRANCH-$REV" - echo "package main" >$VERSIONGO - echo "" >>$VERSIONGO - echo "const (" >>$VERSIONGO - echo -n " FlokatiVersion = \"" >>$VERSIONGO - echo -n "$BRANCH" >>$VERSIONGO - echo "\"" >>$VERSIONGO - echo -n " FlokatiBuild = \"" >>$VERSIONGO - echo -n "$REV" >>$VERSIONGO - echo "\"" >>$VERSIONGO - echo -n " FlokatiBuilddate = \"" >>$VERSIONGO - echo -n "$BUILDDATE" >>$VERSIONGO - echo "\"" >>$VERSIONGO - echo ")" >>$VERSIONGO - cat version.go - docker build -t "$IMAGE:$BRANCH-$REV" . - docker push "$IMAGE:$BRANCH-$REV" - docker tag "$IMAGE:$BRANCH-$REV" "$IMAGE:latest" - docker push "$IMAGE:latest" test: stage: test script: - echo "Testing image $IMAGE:$BRANCH-$REV" deploy: stage: deploy script: - echo "Deploying image $IMAGE:$BRANCH-$REV" - cd ~ - mkdir .ssh - chmod 700 .ssh - echo "$K8S_SSH_PRIVATE_KEY" >.ssh/id_rsa - chmod 600 .ssh/id_rsa - echo "$K8S_SSH_PUBLIC_KEY" >.ssh/id_rsa.pub - chmod 600 .ssh/id_rsa.pub - ssh -oStrictHostKeyChecking=no root@node04 "kubectl set image deployment/mmflokati-flokati mmflokati-flokati=dr.dnix.de/mmflokati:$BRANCH-$REV -n northbrigade" - ssh -oStrictHostKeyChecking=no root@node04 "kubectl set image deployment/mmflokati-armleuchter mmflokati-armleuchter=dr.dnix.de/mmflokati:$BRANCH-$REV -n northbrigade" - ssh -oStrictHostKeyChecking=no root@node04 "kubectl rollout status deployment/mmflokati-flokati -n northbrigade" - ssh -oStrictHostKeyChecking=no root@node04 "kubectl rollout status deployment/mmflokati-armleuchter -n northbrigade" only: - master