Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: [CDE-365]: Send the whole gitspace agent script instead of individual params #510

Merged
merged 3 commits into from
Oct 8, 2024

Conversation

vikyathharekal
Copy link
Collaborator

@vikyathharekal vikyathharekal commented Oct 4, 2024

Description

Since we wanted to send more params for container name, tag, image etc, instead of adding so many params, thought of sending the whole script and appending to the existing one in cloudinit.go
To keep it backward compatible, I haven't removed any existing params.
This would be the script coming from CDE Manager with all the replaced values.

groupadd docker
mkdir -p /mnt/disks/mountdevcontainer/gitspace
export DOCKER_API_VERSION={{ .AgentDockerAPIVersion }}

echo "Updating docker root dir"
systemctl stop docker
mkdir -p /mnt/disks/mountdevcontainer/docker
tee /etc/docker/daemon.json <<EOF
{
  "data-root": "/mnt/disks/mountdevcontainer/docker"
}
EOF
systemctl start docker
echo "Successfully updated docker root dir"

echo "starting gitspaces agent"

# Check if the container is present

if docker ps -a --filter "name={{ .AgentContainerName }}" --quiet | grep -q .; then
    echo "Container {{ .AgentContainerName }} exists. Attempting to start it..."

    # Try to start the container
    docker start {{ .AgentContainerName }}
    if [ $? -ne 0 ]; then
        echo "Failed to start {{ .AgentContainerName }}. Deleting and recreating..."
        docker rm -f {{ .AgentContainerName }}
        echo {{ .AgentContainerRegistryToken }} | docker login -u oauth2accesstoken --password-stdin {{ .AgentContainerRegistry }}
        docker run -p 8083:8083 -v /var/run/docker.sock:/var/run/docker.sock -e DOCKER_API_VERSION={{ .AgentDockerAPIVersion }} -e HARNESS_JWT_SECRET={{ .AgentSecret }} -d --name {{ .AgentContainerName }} {{ .AgentImage }}:{{ .AgentTag }}
    else
        echo "{{ .AgentContainerName }} started successfully."
    fi
else
    echo "Container {{ .AgentContainerName }} does not exist. Creating it..."
    echo {{ .AgentContainerRegistryToken }} | docker login -u oauth2accesstoken --password-stdin {{ .AgentContainerRegistry }}
    docker run -p 8083:8083 -v /var/run/docker.sock:/var/run/docker.sock -e DOCKER_API_VERSION={{ .AgentDockerAPIVersion }} -e HARNESS_JWT_SECRET={{ .AgentSecret }} -d --name {{ .AgentContainerName }} {{ .AgentImage }}:{{ .AgentTag }}
    echo "Agent container started."
fi

echo "done starting gitspaces agent"

Commit Checklist

Thank you for creating a pull request! To help us review / merge this can you make sure that your PR adheres as much as possible to the following.

The Basics

If you are adding new functionality, please provide evidence of the new functionality.

@vikyathharekal vikyathharekal merged commit ffeabc6 into master Oct 8, 2024
1 check passed
@vikyathharekal vikyathharekal deleted the CDE-365 branch October 8, 2024 03:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants