diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 0000000..102247f --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,47 @@ +name: Docker-CI/CD + +on: + push: + branches: + - main + - soc + pull_request: + branches: + - main + - soc +jobs: + deploy: + runs-on: ubuntu-latest + + env: + CI: false + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Run Docker Compose + run: | + cp .env.example .env + docker-compose -f docker-compose.yml up -d + + - name: Authenticate to Google Cloud + uses: google-github-actions/auth@v2 + with: + credentials_json: ${{ secrets.GCP_SA_KEY }} + + - name: Set up gcloud CLI + uses: google-github-actions/auth@v2 + with: + credentials_json: ${{ secrets.GCP_SA_KEY }} + + - name: Check if directory exists on VM + run: | + EXISTS=$(gcloud compute ssh ${{ secrets.GCP_INSTANCE_NAME }} --zone=${{ secrets.GCP_ZONE }} --command="[ -d /SkillWell ] && [ -e /SkillWell/.git ] && echo 'true' || echo 'false'" 2>/dev/null) + + if [ "$EXISTS" = "true" ]; then + echo "Directory already exists on VM. Skipping clone." + else + echo "Directory does not exist on VM. Cloning repository." + gcloud compute ssh "${{ secrets.GCP_INSTANCE_NAME }}" --zone="${{ secrets.GCP_ZONE }}" --command="git clone ${{ secrets.REPO_URL }}" # Use -b to specify the branch + fi