- Clone Bitbucket repository to Gitlab
- Setup repository mirroring on Gitlab point ot Bitbucket
- Add webhook in Bitbucket: https://gitlab.com/api/v4/projects/{{namespaces}}%2F{{project_name}}mirror/pull?private_token={{gitlab_token}}
Last active
April 22, 2022 15:34
-
-
Save hieulm/491f6b6205f4ab58e9f4c23e373da2f6 to your computer and use it in GitHub Desktop.
Gitlab CI/CD, Bitbucket, Docker Swarm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
image: docker:19.03.5 | |
services: | |
- docker:19.03.5-dind | |
before_script: | |
- docker info | |
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY | |
stages: | |
- build | |
- test | |
- release | |
- deploy | |
variables: | |
# DOCKER_HOST: tcp://docker:2375 | |
DOCKER_TLS_CERTDIR: "/certs" | |
DOCKER_DRIVER: overlay2 | |
CONTAINER_TEST_IMAGE: $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA | |
CONTAINER_RELEASE_IMAGE: $CI_REGISTRY_IMAGE:latest | |
CONTAINER_DEV_IMAGE: $CI_REGISTRY_IMAGE:dev | |
build: | |
stage: build | |
script: | |
- echo "$SSH_PRIVATE_KEY" | |
- docker pull $CI_REGISTRY_IMAGE:latest || true | |
- docker build --cache-from $CI_REGISTRY_IMAGE:latest --tag $CONTAINER_TEST_IMAGE . | |
- docker push $CONTAINER_TEST_IMAGE | |
only: | |
- develop | |
unit_tests: | |
stage: test | |
script: | |
- docker pull $CONTAINER_TEST_IMAGE | |
- docker run $CONTAINER_TEST_IMAGE echo "test done" | |
only: | |
- develop | |
release-image-dev: | |
stage: release | |
script: | |
- docker pull $CONTAINER_TEST_IMAGE | |
- docker tag $CONTAINER_TEST_IMAGE $CONTAINER_DEV_IMAGE | |
- docker push $CONTAINER_DEV_IMAGE | |
only: | |
- develop | |
deploy_staging: | |
stage: deploy | |
before_script: | |
- 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )' | |
- eval $(ssh-agent -s) | |
- echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - | |
- mkdir -p ~/.ssh | |
- echo "$SSH_KNOWN_HOSTS" > ~/.ssh/known_hosts | |
- chmod 700 ~/.ssh | |
script: | |
- | | |
ssh $SSH_DEPLOY_USER@$SSH_DEPLOY_HOST /bin/bash -s << EOT | |
echo "Deploy from Gitlab "Deploy from Gitlab CI" | |
cd $CI_CONFIG_DIR | |
docker stack deploy $STACK_NAME -c ./stack.yml --with-registry-auth | |
EOT | |
only: | |
- develop | |
deploy_prod: | |
stage: deploy | |
script: | |
- echo "Deploy to production server" | |
environment: | |
name: production | |
only: | |
- master | |
when: manual |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can you show stack.yml please?