-
-
Save JackShadow/352202bfb08e7dd9317434dde5c5d552 to your computer and use it in GitHub Desktop.
CircleCi golang example
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
version: 2 | |
jobs: | |
test: | |
docker: | |
- image: circleci/golang:1.12 | |
working_directory: ~/go-example/ | |
steps: | |
- checkout | |
- run: go test -cover -v ./... | |
dev_deploy: | |
environment: | |
TARGET_IP: 0.0.0.1 | |
TARGET_DIR: /var/www/deploy-user/go-example | |
REMOTE_USER: deploy-user | |
SERVICE_NAME: go_example | |
docker: | |
- image: circleci/golang:1.12 | |
working_directory: ~/go-example/ | |
steps: | |
- checkout | |
- add_ssh_keys | |
- run: go build -ldflags "-X main.version=$CIRCLE_TAG" -o ./main ./src/main | |
- run: ssh -o "StrictHostKeyChecking=no" $REMOTE_USER@$TARGET_IP "mkdir $TARGET_DIR/v$CIRCLE_TAG" | |
- run: scp main $REMOTE_USER@$TARGET_IP:$TARGET_DIR/v$CIRCLE_TAG/ | |
- run: sed "s/PH_NAME/$SERVICE_NAME/g" .circleci/supervisor_ph.conf > .circleci/$SERVICE_NAME.conf | |
- run: echo command=$TARGET_DIR/v$CIRCLE_TAG/main >> .circleci/$SERVICE_NAME.conf | |
- run: scp .circleci/$SERVICE_NAME.conf $REMOTE_USER@$TARGET_IP:$TARGET_DIR/v$CIRCLE_TAG/ | |
- run: ssh $REMOTE_USER@$TARGET_IP "ln -sf $TARGET_DIR/v$CIRCLE_TAG/$SERVICE_NAME.conf /etc/supervisord.d" | |
- run: ssh $REMOTE_USER@$TARGET_IP "supervisorctl -c /etc/supervisord.conf reread && supervisorctl -c /etc/supervisord.conf update" | |
- run: curl "$TELEGRAM_SERVICE?msg=$SERVICE_NAME%20v$CIRCLE_TAG%20deployed&channel=go_deploy" | |
- run: | |
command: curl "$TELEGRAM_SERVICE?msg=$SERVICE_NAME%20v$CIRCLE_TAG%20failed" | |
when: on_fail | |
prod_deploy: | |
environment: | |
TARGET_IP: 0.0.0.2 | |
TARGET_DIR: /var/www/deploy-user/go-example | |
REMOTE_USER: deploy-user | |
SERVICE_NAME: go_example_prod | |
docker: | |
- image: circleci/golang:1.12 | |
working_directory: ~/go-example/ | |
steps: | |
- checkout | |
- add_ssh_keys | |
- run: go build -ldflags "-X main.version=$CIRCLE_TAG" -o ./main ./src/main | |
- run: ssh -o "StrictHostKeyChecking=no" $REMOTE_USER@$TARGET_IP "mkdir $TARGET_DIR/v$CIRCLE_TAG" | |
- run: scp main $REMOTE_USER@$TARGET_IP:$TARGET_DIR/v$CIRCLE_TAG/ | |
- run: sed "s/PH_NAME/$SERVICE_NAME/g" .circleci/supervisor_ph.conf > .circleci/$SERVICE_NAME.conf | |
- run: echo command=$TARGET_DIR/v$CIRCLE_TAG/main >> .circleci/$SERVICE_NAME.conf | |
- run: scp .circleci/$SERVICE_NAME.conf $REMOTE_USER@$TARGET_IP:$TARGET_DIR/v$CIRCLE_TAG/ | |
- run: ssh $REMOTE_USER@$TARGET_IP "ln -sf $TARGET_DIR/v$CIRCLE_TAG/$SERVICE_NAME.conf /etc/supervisord.d" | |
- run: ssh $REMOTE_USER@$TARGET_IP "supervisorctl -c /etc/supervisord.conf reread && supervisorctl -c /etc/supervisord.conf update" | |
- run: curl "$TELEGRAM_SERVICE?msg=$SERVICE_NAME%20v$CIRCLE_TAG%20deployed&channel=go_deploy" | |
- run: | |
command: curl "$TELEGRAM_SERVICE?msg=$SERVICE_NAME%20v$CIRCLE_TAG%20failed" | |
when: on_fail | |
workflows: | |
version: 2 | |
tagged-build: | |
jobs: | |
- test: | |
filters: | |
branches: | |
ignore: /.*/ | |
tags: | |
only: /.*/ | |
- dev_deploy: | |
requires: | |
- test | |
filters: | |
branches: | |
ignore: /.*/ | |
tags: | |
only: /.*/ | |
- approve_master_deploy: | |
type: approval | |
requires: | |
- test | |
filters: | |
branches: | |
ignore: /.*/ | |
tags: | |
only: /.*/ | |
- prod_deploy: | |
requires: | |
- dev_deploy | |
- approve_master_deploy | |
filters: | |
branches: | |
ignore: /.*/ | |
tags: | |
only: /.*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment