Skip to content

Instantly share code, notes, and snippets.

@rust20
Created April 2, 2019 04:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rust20/853d86dbfa818c08f842bac9c964d336 to your computer and use it in GitHub Desktop.
Save rust20/853d86dbfa818c08f842bac9c964d336 to your computer and use it in GitHub Desktop.
complete gitlab CI
stages:
- test
- lint
- deploy
variables:
DOCKER_REGISTRY: "registry.docker.ppl.cs.ui.ac.id/ppla4"
API_IMAGE: "yuk-recycle-api"
cache:
key: ${CI_COMMIT_REF_SLUG}
paths:
- /go/bin/
- /go/src/
backend:test:
image: golang
stage: test
coverage: '/total:\s+\(statements\)\s+\d+\.\d+\%/'
cache:
key: ${CI_COMMIT_REF_SLUG}
script:
# prepare test environment
- export GOWORKDIR=$GOPATH/src/PPLA4
- mkdir -p $GOWORKDIR
- ln -svf $CI_PROJECT_DIR/backend $GOWORKDIR
- cd $GOWORKDIR/backend
- mkdir coverage
# install dependencies
- go get -t ./...
# testing
- go test ./... -coverprofile=coverage/coverage.out
- go tool cover -func=coverage/coverage.out
- go tool cover -html=coverage/coverage.out -o coverage/coverage.html
artifacts:
paths:
- backend/coverage
only:
changes:
- backend/**/*
- .gitlab-ci.yml
backend:lint:
image: golang
stage: lint
dependencies:
- backend:test
cache:
key: ${CI_COMMIT_REF_SLUG}
script:
- cd backend
- go get golang.org/x/lint/golint
- golint ./...
.deploy:backend: &deploy_backend_template
image: gitlab/dind:latest
stage: deploy
tags:
- docker
dependencies:
- backend:test
cache:
key: ${CI_COMMIT_REF_SLUG}
before_script:
- mkdir -p /go/src
- ln -s /go/src/ backend/src
- cd backend
- docker-compose build
backend:deploy-dev:
<<: *deploy_backend_template
variables:
VER: "dev"
script:
- docker tag $DOCKER_REGISTRY/$API_IMAGE:latest $DOCKER_REGISTRY/$API_IMAGE:dev
- docker push $DOCKER_REGISTRY/$API_IMAGE:dev
only:
changes:
- backend/**/*
- .gitlab-ci.yml
refs:
- development
backend:deploy-staging:
<<: *deploy_backend_template
variables:
VER: "staging"
script:
- docker tag $DOCKER_REGISTRY/$API_IMAGE:latest $DOCKER_REGISTRY/$API_IMAGE:staging
- docker push $DOCKER_REGISTRY/$API_IMAGE:staging
only:
changes:
- backend/**/*
- .gitlab-ci.yml
refs:
- staging
.mobile:unit-test: &unit-test-mobile
image: rust20/flutter-build:latest
stage: test
coverage: '/lines......: \d+\.\d+\%/'
variables:
APP: ""
script:
- cd mobile/$APP
- flutter doctor -v
- flutter test --coverage
- lcov --summary coverage/lcov.info
- genhtml coverage/lcov.info --output=coverage
mitra:unit-test:
<<: *unit-test-mobile
variables:
APP: "mitra_app"
artifacts:
paths:
- mobile/mitra_app/coverage/
only:
changes:
- mobile/mitra_app/**/*
- .gitlab-ci.yml
customer:unit-test:
<<: *unit-test-mobile
variables:
APP: "customer_app"
artifacts:
paths:
- mobile/customer_app/coverage/
only:
changes:
- mobile/customer_app/**/*
- .gitlab-ci.yml
# For future CD job if required
.mobile:build: &mobile-build
image: rust20/flutter-build:latest
stage: deploy
script:
- cd mobile/$APP
- flutter build apk
artifacts:
- build/app/outputs/apk/release/app-release.apk
mitra:build:
<<: *mobile-build
dependencies:
- mitra:unit-test
variables:
APP: "mitra_app"
artifacts:
paths:
- mobile/mitra_app/build/app/outputs/apk/release/app-release.apk
only:
refs:
- staging
- development
changes:
- mobile/mitra_app/**/*
- .gitlab-ci.yml
customer:build:
<<: *mobile-build
dependencies:
- customer:unit-test
variables:
APP: "customer_app"
artifacts:
paths:
- mobile/customer_app/build/app/outputs/apk/release/app-release.apk
only:
refs:
- staging
- development
changes:
- mobile/customer_app/**/*
- .gitlab-ci.yml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment