Skip to content

Commit

Permalink
Updated run script and added compose file
Browse files Browse the repository at this point in the history
  • Loading branch information
dbecker1 committed Oct 18, 2018
1 parent 7fe80a3 commit 0b2065e
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# This Dockerfile is used to build an headles vnc image based on Ubuntu
# This Dockerfile is used to build an headles vnc image based on Ubuntu

FROM ubuntu:18.04

Expand Down
27 changes: 27 additions & 0 deletions checkUpdate/checkUpdate.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include <stdio.h>
#include <curl/curl.h>

int main(void) {
CURL *curl;
CURLcode res;

curl_global_init(CURL_GLOBAL_DEFAULT);

curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, "https://registry-1.docker.io/v2/dbecker1/cs2110docker/tags/list");
/* Perform the request, res will get the return code */
res = curl_easy_perform(curl);
/* Check for errors */
if(res != CURLE_OK)
fprintf(stderr, "curl_easy_perform() failed: %s\n",
curl_easy_strerror(res));

/* always cleanup */
curl_easy_cleanup(curl);
}

curl_global_cleanup();

return 0;
}
51 changes: 51 additions & 0 deletions checkUpdate/checkUpdate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import urllib.request, urllib.parse, urllib.error
import json
import os
from subprocess import call

authUrl = "https://auth.docker.io/token?service=registry.docker.io&scope=repository:dbecker1/cs2110docker:pull"

authResponse = urllib.request.urlopen(authUrl)
authData = authResponse.read().decode()

try:
authJs = json.loads(authData)
except:
authJs = None

imageDataUrl = "https://registry-1.docker.io/v2/dbecker1/cs2110docker/tags/list";
dataRequest = urllib.request.Request(imageDataUrl)

dataRequest.add_header('Authorization', "Bearer " + authJs["token"]);

dataResponse = urllib.request.urlopen(dataRequest)
imageData = dataResponse.read().decode()

try:
imageJs = json.loads(imageData)
except:
imageJs = None

tags = imageJs["tags"]
mostRecentTag = "0.0.0"

for tag in tags:
if tag == "latest":
continue
tag1Split = mostRecentTag.split(".")
tag2Split = tag.split(".")
i = 0
if i < len(tag1Split) and i < len(tag2Split):
if int(tag1Split[i]) < int(tag2Split[i]):
mostRecentTag = tag
break
elif len(tag2Split) > len(tag1Split):
mostRecentTag = tag
break

currentVersion = os.environ['CS2110_IMAGE_VERSION']

if mostRecentTag != currentVersion:
call(["notify-send", "'Update Docker Image'", "'Hello, your TAs have pushed an update to this Docker Image. In order to ensure you have the latest and greatest, please re-run the cs2110docker.sh script'"])
else:
print("Docker image is up to date")
4 changes: 2 additions & 2 deletions cs2110docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fi
echo Found Docker Installation. Checking for existing containers.

existingContainers=$(docker ps -a | grep $imageName | awk '{print $1}')

echo $existingContainers
if [ $existingContainers ]; then
echo Found CS 2110 containers. Stopping and removing them.
docker stop $existingContainers >/dev/null
Expand All @@ -48,7 +48,7 @@ fi
echo Starting up new CS 2110 Docker Container:

if [ "$1" == "-it" ]; then
docker run -p 6901:6901 -p 5901:5901 -v "$(pwd)":/cs2110/host/ -it --entrypoint /bin/bash dbecker1/cs2110docker
docker run --rm -p 6901:6901 -p 5901:5901 -v "$(pwd)":/cs2110/host/ -it --entrypoint /bin/bash dbecker1/cs2110docker
else
docker run -d -p 6901:6901 -p 5901:5901 -v "$(pwd)":/cs2110/host/ dbecker1/cs2110docker

Expand Down
3 changes: 3 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
services:
cs2110docker:
build: https://github.com/dbecker1/cs2110docker

0 comments on commit 0b2065e

Please sign in to comment.