Last active
July 27, 2023 14:33
-
-
Save rodrigobertin/5dbf5e34a939946a108c883495c0536c to your computer and use it in GitHub Desktop.
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
## Build angular site | |
- name: build | |
pull: if-not-exists | |
image: node:16.18.1-alpine | |
when: | |
branch: | |
- master | |
event: | |
- push | |
commands: | |
- npm install --legacy-peer-deps | |
- npm run build --prod |
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
- name: clone_repo | |
when: | |
branch: | |
- master | |
event: | |
- push | |
image: appleboy/drone-ssh | |
failure: ignore | |
settings: | |
host: | |
from_secret: SSH_HOST | |
username: root | |
key: | |
from_secret: PRIVATE_KEY | |
port: 44200 | |
command_timeout: 3m | |
envs: | |
- FOLDER_DEST | |
- SERVER | |
- CLONE_TOKEN | |
- CONTAINER | |
- REPO_URL | |
script: | |
- export FOLDER_DEST=$FOLDER_DEST | |
- export CLONE_TOKEN=$CLONE_TOKEN | |
- export CONTAINER=$CONTAINER | |
- export REPO_URL=$REPO_URL | |
- git clone https://oauth2:$CLONE_TOKEN@$REPO_URL $FOLDER_DEST |
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
- name: test | |
when: | |
branch: | |
- main | |
event: | |
- push | |
image: docker:dind | |
environment: | |
DOCKER_PASSWORD: | |
from_secret: GITLAB_PASSWORD | |
REGISTRY: <image_docker> | |
DOCKER_USER: <user> | |
volumes: | |
- name: dockersock | |
path: /var/run | |
commands: | |
- sleep 5 # give docker enough time to start | |
- docker ps -a | |
- docker login -u "$DOCKER_USER" -p "$DOCKER_PASSWORD" registry.gitlab.com | |
- docker buildx create --use | |
- docker buildx build --push --platform linux/arm64/v8,linux/amd64 --pull -t $REGISTRY:multi . | |
services: | |
- name: docker | |
image: docker:dind | |
privileged: true | |
volumes: | |
- name: dockersock | |
path: /var/run | |
volumes: | |
- name: dockersock | |
temp: {} |
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
## Create docker image | |
- name: docker-image-arm | |
image: plugins/docker | |
when: | |
branch: | |
- master | |
event: | |
- push | |
settings: | |
username: <user> | |
password: | |
from_secret: GITLAB_PASSWORD | |
repo: registry.gitlab.com/<user>/bioccasi.com | |
registry: registry.gitlab.com | |
platform: linux/arm64 |
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
kind: pipeline | |
type: docker | |
name: default | |
platform: | |
os: linux | |
arch: arm64 | |
trigger: | |
branch: | |
- master | |
event: | |
- push | |
environment: | |
SERVER: <server_url> | |
CLONE_TOKEN: | |
from_secret: CLONE_TOKEN | |
CONTAINER: <container_name> | |
FOLDER_DEST: <folder_dest> | |
REPO_URL: <repo_url> | |
steps: | |
## Clone repo in VPS | |
- name: clone | |
image: appleboy/drone-ssh | |
failure: ignore | |
settings: | |
host: | |
- <server_url> | |
username: root | |
key: | |
from_secret: PRIVATE_KEY | |
port: 44200 | |
command_timeout: 3m | |
envs: | |
- FOLDER_DEST | |
- CLONE_TOKEN | |
- REPO_URL | |
script: | |
- export FOLDER_DEST=$FOLDER_DEST | |
- export CLONE_TOKEN=$CLONE_TOKEN | |
- export REPO_URL=$REPO_URL | |
- git clone https://oauth2:$CLONE_TOKEN@$REPO_URL $FOLDER_DEST | |
## Update repo in VPS | |
- name: update | |
image: appleboy/drone-ssh | |
settings: | |
host: | |
- <server_url> | |
username: root | |
key: | |
from_secret: PRIVATE_KEY | |
port: 44200 | |
command_timeout: 3m | |
envs: | |
- FOLDER_DEST | |
script: | |
- export FOLDER_DEST=$FOLDER_DEST | |
- cd $FOLDER_DEST && git pull origin master -f && git gc --prune=now --aggressive | |
## Rebuild and restart | |
- name: deploy | |
image: appleboy/drone-ssh | |
settings: | |
host: | |
- <server_url> | |
username: root | |
key: | |
from_secret: PRIVATE_KEY | |
port: 44200 | |
command_timeout: 3m | |
envs: | |
- FOLDER_DEST | |
- CONTAINER | |
script: | |
- export FOLDER_DEST=$FOLDER_DEST | |
- export CONTAINER=$CONTAINER | |
- docker-compose -f $FOLDER_DEST/docker-compose-prod.yml build --force | |
- docker-compose -f $FOLDER_DEST/docker-compose-prod.yml down | |
- docker-compose -f $FOLDER_DEST/docker-compose-prod.yml up -d | |
- docker exec -i $CONTAINER python manage.py migrate | |
- docker exec -i $CONTAINER python manage.py collectstatic --noinput --clear --ignore *.scss | |
- docker system prune -f |
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
kind: pipeline | |
type: docker | |
name: default | |
platform: | |
os: linux | |
arch: arm64 | |
trigger: | |
branch: | |
- master | |
event: | |
- push | |
steps: | |
- name: deploy | |
image: rodrigobertin/drone-rsync | |
settings: | |
port: 44200 | |
user: root | |
key: | |
from_secret: PRIVATE_KEY | |
hosts: [ "ssh.server.com" ] | |
delete: true | |
exclude: ['.git','.idea','*.pyc'] | |
source: ./ | |
target: /tmp/TEST | |
script: | |
- ls -la /tmp/TEST | |
- echo "--- Finalizado ---->" |
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
## Execute SSH | |
- name: deploy | |
image: alpine | |
pull: if-not-exists | |
environment: | |
PRIVATE_KEY: | |
from_secret: PRIVATE_KEY | |
when: | |
branch: | |
- master | |
event: | |
- push | |
commands: | |
- apk update | |
- apk add rsync | |
- 'which ssh-agent || ( apk add openssh-client )' | |
- eval $(ssh-agent -s) | |
- ssh-add <(echo "$PRIVATE_KEY") | |
- mkdir -p ~/.ssh | |
- '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config' | |
- rsync -rvz -e 'ssh -p 44200' dist/bioccasi_frontend/ root@$SERVER:$RUTA/ --delete |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment