changes #51
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: 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: SSH into the VM and List Repository Directory | |
# run: | | |
# REPO_PATH=~ | |
# # SSH into the VM and clone the repo | |
# gcloud compute ssh ${{ secrets.GCP_INSTANCE_NAME}} --zone=${{ secrets.GCP_ZONE }} --command " | |
# REPO_PATH=\$HOME | |
# if [ ! -d \"\$REPO_PATH\" ]; then | |
# git clone ${{github.repositoryUrl}} && cd woc && sudo apt-get update && sudo apt-get install -y nginx && sudo service nginx status && sudo apt update && sudo apt install -y apt-transport-https ca-certificates curl software-properties-common && curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - && sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable" && apt-cache policy docker-ce && sudo apt install -y docker-ce && sudo systemctl status docker && sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose && sudo chmod +x /usr/local/bin/docker-compose && docker-compose --version \$REPO_PATH | |
# else | |
# echo \"Repository already exists. Skipping clone.\" | |
# fi | |
# " | |
# - name: SSH into the VM and build the Docker image | |
# env: | |
# CI: false | |
# run: | | |
# # SSH into the VM and clone the repo | |
# gcloud compute ssh ${{ secrets.GCP_INSTANCE_NAME}} --zone=${{ secrets.GCP_ZONE }} --command 'cd woc && git checkout soc && cp .env.example .env && sudo docker-compose -f docker-compose.yml up -d' | |
- name: SSH into the VM and edit the nginx file | |
env: | |
CI: false | |
run: | | |
# Set up gcloud credentials (replace with your appropriate setup) | |
echo "$GCP_SERVICE_ACCOUNT_KEY" > /tmp/keyfile.json | |
gcloud auth activate-service-account --key-file=/tmp/keyfile.json | |
gcloud config set project $GCP_PROJECT_ID | |
# SSH into the VM and edit the file | |
gcloud compute ssh ${{ secrets.GCP_INSTANCE_NAME}} --zone=${{ secrets.GCP_ZONE }} --command ' | |
cd /etc/nginx/sites-enabled && | |
ls -l && | |
sudo sed -i "s/^try_files \$uri \$uri\/ =404;/# &/" default && | |
sudo sed -i "/# try_files \$uri \$uri\/ =404;/a \ proxy_pass http://localhost8000;" default && | |
sudo systemctl restart nginx | |
' | |
# - name: SSH into the VM and do the necessary changes in the nginx file for hosting the docker container | |
# run: | | |
# # SSH into the VM and clone the repo | |
# gcloud compute ssh ${{ secrets.GCP_INSTANCE_NAME}} --zone=${{ secrets.GCP_ZONE }} --command 'cd woc && cd /etc/nginx/sites-enabled' | |