Skip to content

Commit e62a526

Browse files
committed
add docker image update function
1 parent 4adab86 commit e62a526

File tree

4 files changed

+31
-10
lines changed

4 files changed

+31
-10
lines changed

builds/setup-darwin-amd64.bin

264 KB
Binary file not shown.

builds/setup-linux-amd64.bin

262 KB
Binary file not shown.

builds/setup-windows-amd64.exe

429 KB
Binary file not shown.

setup/main.go

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ var (
2323
errCopyFile = errors.New("FAILED TO COPY DOCKER-COMPSE-PROD.YML")
2424
errCloneRepo = errors.New("FAILED TO CLONE THE REPOSITORY")
2525
errDockerCheck = errors.New("DOCKER IS NOT INSTALLED")
26-
errSetupCheck = errors.New("SETUP CHECK FAILED")
2726
errDockerComposeRun = errors.New("FAILED TO RUN DOCKER-COMPOSE")
27+
errDockerImageUpdate = errors.New("FAILED TO UPDATE THE DOCKER IMAGE")
28+
errSetupCheck = errors.New("SETUP CHECK FAILED")
2829
errReviewsNotEmpty = errors.New("REVIEWS DIRECTORY IS NOT EMPTY")
2930
errMissingSourceFiles = errors.New("MISSING SOURCE FILES")
3031
errInputScrapMode = errors.New("INVALID SCRAP MODE")
@@ -41,14 +42,20 @@ func main() {
4142
errorHandler(err)
4243
fmt.Println("0. " + msg)
4344

45+
// Check if the image already exists
46+
fmt.Println("1. Downloading / Updating Dokcer Image")
47+
msg, err = updateDockerImage()
48+
errorHandler(err)
49+
fmt.Println("1.1 " + msg)
50+
4451
// Get the current directory
4552
currentDir, err := getCurrentDir()
4653

4754
// Check for errors
4855
errorHandler(err)
4956

5057
// Print the current directory
51-
fmt.Println("1. Current directory: ", currentDir)
58+
fmt.Println("2. Current directory: ", currentDir)
5259

5360
// Run the setup check
5461
isCompleted, err := setupCheck(currentDir)
@@ -75,7 +82,7 @@ func main() {
7582
tmpDirFullPath := filepath.Join(currentDir, tmpDirName)
7683

7784
// Print the message
78-
fmt.Println("2. Tmp Directory created:", tmpDirFullPath)
85+
fmt.Println("3. Tmp Directory created:", tmpDirFullPath)
7986

8087
// Create a temporary directory to hold the repository
8188
projectDirName, err := createDirectory("Project_Files")
@@ -86,14 +93,14 @@ func main() {
8693
projectDirFullPath := filepath.Join(currentDir, projectDirName)
8794

8895
// Print the message
89-
fmt.Println("3. Project Directory created:", projectDirFullPath)
96+
fmt.Println("4. Project Directory created:", projectDirFullPath)
9097

9198
// Call the clone repo function
9299
msg, err = cloneRepo(tmpDirFullPath)
93100

94101
// Check for errors
95102
errorHandler(err)
96-
fmt.Println("4. " + msg)
103+
fmt.Println("5. " + msg)
97104

98105
// Copy docker-compose-prod.yml to the Project_Files directory
99106
msg, err = copy(
@@ -102,13 +109,13 @@ func main() {
102109

103110
// Check for errors
104111
errorHandler(err)
105-
fmt.Println("5. " + msg)
112+
fmt.Println("6. " + msg)
106113

107114
// Purge the temporary directory
108115
msg, err = purgeDir(tmpDirFullPath)
109116
// Check for errors
110117
errorHandler(err)
111-
fmt.Println("6. " + msg)
118+
fmt.Println("7. " + msg)
112119

113120
// Create the source directory
114121
sourceDirFullPath := filepath.Join(projectDirFullPath, "source")
@@ -118,7 +125,7 @@ func main() {
118125
errorHandler(err)
119126

120127
// Print the message
121-
fmt.Println("7. Source Directory created:", sourceDirFullPath)
128+
fmt.Println("8. Source Directory created:", sourceDirFullPath)
122129

123130
// Create the reviews directory
124131
reviewsDirFullPath := filepath.Join(projectDirFullPath, "reviews")
@@ -128,7 +135,7 @@ func main() {
128135
errorHandler(err)
129136

130137
// Print the message
131-
fmt.Println("8. Reviews Directory created:", reviewsDirFullPath)
138+
fmt.Println("9. Reviews Directory created:", reviewsDirFullPath)
132139

133140
// Notify the user that the setup has been completed
134141
fmt.Println("Setup Completed. Please place the source files in the source directory and restart the program.")
@@ -282,6 +289,20 @@ func checkDocker() (string, error) {
282289
return "Docker is installed", nil
283290
}
284291

292+
// Update the docker image if already exist
293+
func updateDockerImage() (string, error) {
294+
295+
cmd := exec.Command("docker", "pull", "ghcr.io/algo7/tripadvisor-review-scraper/scrap:latest")
296+
297+
err := cmd.Run()
298+
299+
if err != nil {
300+
return "Ops", errDockerImageUpdate
301+
}
302+
303+
return "All Clear", nil
304+
}
305+
285306
/* Check if the setup process has been completed already
286307
* If it has, spin up the docker container
287308
*/
@@ -377,7 +398,7 @@ func dockerComposeRun(path string) error {
377398
dockerComposePath := filepath.Join(path, "docker-compose-prod.yml")
378399

379400
// Run the docker container
380-
cmd := exec.Command("docker-compose", "-f", dockerComposePath, "up")
401+
cmd := exec.Command("docker", "compose", "-f", dockerComposePath, "up")
381402

382403
// Create a pipe that connects to the stdout of the command
383404
stdout, err := cmd.StdoutPipe()

0 commit comments

Comments
 (0)