-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreateGoProject.sh
More file actions
77 lines (52 loc) · 1.66 KB
/
CreateGoProject.sh
File metadata and controls
77 lines (52 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/bin/bash
read -p "Enter the name of your Docker/Golang project: " project_name
# Replace spaces with hyphens and convert to lowercase
project_name_safe=$(echo "$project_name" | tr '[:upper:]' '[:lower:]' | tr ' ' '-')
# Create project directory
mkdir "$project_name_safe"
cd "$project_name_safe"
# Create src folder
mkdir src
# Create a simple Go source file
echo 'package main
import "fmt"
func main() {
fmt.Println("Hello, Docker/Golang World!")
}' > src/main.go
# Initialize go module
go mod init "$project_name_safe"
# Create Dockerfile
echo "FROM golang:latest
WORKDIR /go/src
COPY . .
RUN go get -d -v ./...
RUN go install -v ./...
# Explicitly build the executable
RUN go build -o app ./src
CMD [\"./app\"]" > Dockerfile
# Create .github/workflows directory
mkdir -p .github/workflows
# Create GitHub Actions workflow file
echo "name: Build Docker Image
on:
push:
schedule:
- cron: '0 0 * * *'
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Test Build Docker image
run: docker build -t cgp-github-test ." > .github/workflows/main.yml
echo "Project created successfully in the '$project_name_safe' directory."
# Instructions
echo "
To build and run the project using Docker:
1. Build the Docker image:
docker build -t $project_name_safe .
2. Run the Docker container:
docker run $project_name_safe
Note: If your project name contains spaces, replace them with hyphens in Docker commands.
GitHub Actions workflow is set up to build the Docker image on every commit and once every 24 hours. Check the status on the 'Actions' tab in your GitHub repository."