Skip to content

Instantly share code, notes, and snippets.

@olekhy
Created January 26, 2024 12:35
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 olekhy/97ae249077dbc1366eef60f76af16942 to your computer and use it in GitHub Desktop.
Save olekhy/97ae249077dbc1366eef60f76af16942 to your computer and use it in GitHub Desktop.
example

stages:

  • deploy

variables: AWS_DEFAULT_REGION: "your-aws-region" ECS_CLUSTER: "your-ecs-cluster" ECS_SERVICE_NAME: "your-ecs-service-name" ECS_TASK_DEFINITION: "your-ecs-task-definition" IMAGE_TAG: "latest"

deploy: stage: deploy script: - aws ecr get-login-password --region $AWS_DEFAULT_REGION | docker login --username AWS --password-stdin your-aws-account-id.dkr.ecr.your-aws-region.amazonaws.com - docker-compose build - docker tag your-php-image:latest your-aws-account-id.dkr.ecr.your-aws-region.amazonaws.com/your-php-image:$IMAGE_TAG - docker tag your-react-image:latest your-aws-account-id.dkr.ecr.your-aws-region.amazonaws.com/your-react-image:$IMAGE_TAG - docker push your-aws-account-id.dkr.ecr.your-aws-region.amazonaws.com/your-php-image:$IMAGE_TAG - docker push your-aws-account-id.dkr.ecr.your-aws-region.amazonaws.com/your-react-image:$IMAGE_TAG - aws ecs update-service --cluster $ECS_CLUSTER --service $ECS_SERVICE_NAME --force-new-deployment

@olekhy
Copy link
Author

olekhy commented Jan 26, 2024

stages:
  - deploy

variables:
  SSH_PRIVATE_KEY: $CI_DEPLOY_PRIVATE_KEY
  SSH_HOST: "your-ec2-instance-ip"
  SSH_USER: "ec2-user"
  COMPOSE_FILE: "docker-compose.yml"
  APP_PATH: "/path/to/your/app"

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 -

deploy:
  stage: deploy
  script:
    - scp -r -o StrictHostKeyChecking=no $COMPOSE_FILE $SSH_USER@$SSH_HOST:$APP_PATH
    - ssh $SSH_USER@$SSH_HOST "cd $APP_PATH && docker-compose pull && docker-compose up -d"
    - ssh $SSH_USER@$SSH_HOST "cd $APP_PATH && docker-compose exec web php artisan migrate"
  only:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment