Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
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
- setup-ci-cd
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
22 changes: 22 additions & 0 deletions deploy.sh
Original file line number Diff line number Diff line change
@@ -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