@@ -2,19 +2,66 @@ name: Go
2
2
on :
3
3
push :
4
4
branches :
5
- - sonarcloud
5
+ - digitalocean
6
6
pull_request :
7
7
types : [opened, synchronize, reopened]
8
8
jobs :
9
- sonarcloud :
10
- name : SonarCloud
9
+ # This workflow contains a single job called "build".
10
+ build :
11
+ # The type of runner that the job will run on.
11
12
runs-on : ubuntu-latest
13
+
14
+ # Steps represent a sequence of tasks that will be executed as part of the job
12
15
steps :
13
- - uses : actions/checkout@v2
14
- with :
15
- fetch-depth : 0 # Shallow clones should be disabled for a better relevancy of analysis
16
- - name : SonarCloud Scan
17
- uses : SonarSource/sonarcloud-github-action@master
18
- env :
19
- GITHUB_TOKEN : ${{ secrets.GH_TOKEN }} # Needed to get PR information, if any
20
- SONAR_TOKEN : ${{ secrets.SONAR_TOKEN }}
16
+
17
+ # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it.
18
+ - name : Checkout master
19
+ uses : actions/checkout@main
20
+
21
+ - name : Setup-Golang
22
+ uses : actions/setup-go@v4
23
+ with :
24
+ go-version : ' 1.23'
25
+ check-latest : true
26
+ - run : go version
27
+ - name : Build-Golang-App
28
+ run : GOOS=linux go build web.go
29
+ - name : Display-Build-Golang-App
30
+ run : ls -l web
31
+
32
+ # Install doctl.
33
+ - name : Install doctl
34
+ uses : digitalocean/action-doctl@v2
35
+ with :
36
+ token : ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}
37
+
38
+ # Build a Docker image of your application in your registry and tag the image with the $GITHUB_SHA.
39
+ - name : Build container image
40
+ run : docker build -t ${{ secrets.REGISTRY_NAME }}/golang-web:$(echo $GITHUB_SHA | head -c7) .
41
+
42
+ - name : Log in to DigitalOcean Container Registry with short-lived credentials
43
+ run : doctl registry login --expiry-seconds 1200
44
+
45
+ - name : Push image to DigitalOcean Container Registry
46
+ run : docker push ${{ secrets.REGISTRY_NAME }}/golang-web:$(echo $GITHUB_SHA | head -c7)
47
+
48
+ # Deploy to DigitalOCcean Kubernetes.
49
+ - name : Update deployment file
50
+ run : TAG=$(echo $GITHUB_SHA | head -c7) && sed -i 's|<IMAGE>|${{ secrets.REGISTRY_NAME }}/golang-web:'${TAG}'|' $GITHUB_WORKSPACE/deployment.yml
51
+
52
+ - name : Save DigitalOcean kubeconfig with short-lived credentials
53
+ run : doctl kubernetes cluster kubeconfig save --expiry-seconds 600 ${{ secrets.CLUSTER_NAME }}
54
+
55
+ # If you haven't already integrated with your registry and only want workloads in a particular namespace to be able to pull
56
+ # from your registry, uncomment the next two commands.
57
+ # - name: Upload credentials of your registry to your DigitalOcean Kubernetes cluster
58
+ # run: doctl registry kubernetes-manifest | kubectl apply -f -
59
+
60
+ # - name: Reference the secret you just uploaded as an imagePullSecrets
61
+ # run: "kubectl patch serviceaccount default -p '{\"imagePullSecrets\": [{\"name\": \"registry-<your-registry-name>`\"}]}'"
62
+
63
+ - name : Deploy to DigitalOcean Kubernetes
64
+ run : kubectl apply -f $GITHUB_WORKSPACE/deployment.yml
65
+
66
+ - name : Verify deployment
67
+ run : kubectl rollout status deployment/golang-web
0 commit comments