From 88674e321a49b0f063b804246e5e5bde33222a2a Mon Sep 17 00:00:00 2001 From: Nebiyu Getachew Gelaw Date: Sat, 25 May 2024 17:22:20 +0300 Subject: [PATCH 1/2] Add CI/CD pipeline configuration --- .gitlab-ci.yml | 33 +++++++++++++++++++++++++++++++++ deploy.sh | 22 ++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 .gitlab-ci.yml create mode 100644 deploy.sh diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..8ac6b15 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,33 @@ +stages: + - test + - deploy + +variables: + DOCKER_DRIVER: overlay2 + +cache: + paths: + - node_modules/ + +test: + stage: test + image: node:18 + script: + - npm install + - npm run test + only: + - merge_requests + - Test + +deploy: + stage: deploy + image: docker:20.10.7 + services: + - docker:20.10.7-dind + before_script: + - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY + - apk add --no-cache bash + script: + - bash deploy.sh + only: + - main \ No newline at end of file diff --git a/deploy.sh b/deploy.sh new file mode 100644 index 0000000..bdb2e0e --- /dev/null +++ b/deploy.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +# Navigate to the Terraform directory +cd terraform + +# Initialize Terraform +terraform init + +# Apply the Terraform scripts +terraform apply -auto-approve + +# Get the Droplet IP from Terraform +DROPLET_IP=$(terraform output -raw droplet_ip) + +# Navigate to the Docker directory +cd ../docker + +# Set environment variables +export DROPLET_IP=$DROPLET_IP + +# Deploy the Docker stack +docker -H tcp://$DROPLET_IP:2376 stack deploy -c docker-compose.yml myapp \ No newline at end of file From 1bba49baac26bb7e637215a8ba544f61f001ed84 Mon Sep 17 00:00:00 2001 From: Nebiyu Getachew <146662023+Nebiyu-0791@users.noreply.github.com> Date: Sat, 25 May 2024 17:36:02 +0300 Subject: [PATCH 2/2] Update .gitlab-ci.yml --- .gitlab-ci.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 8ac6b15..35c53f6 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -17,8 +17,7 @@ test: - npm run test only: - merge_requests - - Test - + - setup-ci-cd deploy: stage: deploy image: docker:20.10.7 @@ -30,4 +29,4 @@ deploy: script: - bash deploy.sh only: - - main \ No newline at end of file + - main