-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from Ulas-Scan/4-swagger
4 swagger
- Loading branch information
Showing
6 changed files
with
132 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
name: Deploy to GCE | ||
|
||
env: | ||
APP_NAME: ulascan-be | ||
GCE_INSTANCE_IP: ${{ secrets.GCE_INSTANCE_IP }} | ||
GCE_INSTANCE_NAME: ${{ secrets.GCE_INSTANCE_NAME }} | ||
GCP_PROJECT_ID: ${{ secrets.GCP_PROJECT_ID }} | ||
GCP_SA_KEY: ${{ secrets.GCP_SA_KEY }} | ||
GCP_ZONE: ${{ secrets.GCP_ZONE }} | ||
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v1 | ||
|
||
- name: Authenticate to Google Cloud | ||
uses: google-github-actions/auth@v1 | ||
with: | ||
credentials_json: ${{ secrets.GCP_SA_KEY }} | ||
|
||
- name: Set up Google Cloud SDK | ||
uses: google-github-actions/setup-gcloud@v1 | ||
with: | ||
project_id: ${{ secrets.GCP_PROJECT_ID }} | ||
|
||
- name: Configure docker for Artifact Registry | ||
run: | | ||
gcloud --quiet auth configure-docker $GCP_ZONE-docker.pkg.dev | ||
- name: Build and push Docker image | ||
run: | | ||
docker build -t $GCP_ZONE-docker.pkg.dev/$GCP_PROJECT_ID/$APP_NAME:latest . | ||
docker push $GCP_ZONE-docker.pkg.dev/$GCP_PROJECT_ID/$APP_NAME:latest | ||
deploy: | ||
needs: build | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Install SSH client | ||
run: sudo apt-get install -y ssh | ||
|
||
- name: Set up SSH | ||
run: | | ||
echo "$SSH_PRIVATE_KEY" > ssh_key | ||
chmod 600 ssh_key | ||
- name: Deploy to GCE | ||
run: | | ||
ssh -o StrictHostKeyChecking=no \ | ||
-i ssh_key \ | ||
ulascan@$GCE_INSTANCE_IP \ | ||
"gcloud --quiet auth configure-docker $GCP_ZONE-docker.pkg.dev \ | ||
&& docker pull $GCP_ZONE-docker.pkg.dev/$GCP_PROJECT_ID/$APP_NAME:latest \ | ||
&& docker stop $APP_NAME || true \ | ||
&& docker rm --force $APP_NAME || true \ | ||
&& docker run -d --name $APP_NAME -p 8080:80 $GCP_ZONE-docker.pkg.dev/$GCP_PROJECT_ID/$APP_NAME:latest \ | ||
&& docker image prune -f" | ||
- name: Cleanup SSH key | ||
run: rm ssh_key |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
FROM golang:latest | ||
|
||
WORKDIR /app | ||
|
||
COPY . . | ||
|
||
RUN go mod download && go mod verify | ||
|
||
RUN go build -v -o main . | ||
|
||
EXPOSE 8080 | ||
|
||
CMD ["/app/main"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package middleware | ||
|
||
import ( | ||
"github.com/gin-gonic/gin" | ||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
func Logger() gin.HandlerFunc { | ||
return func(c *gin.Context) { | ||
// Log incoming request | ||
logrus.WithFields(logrus.Fields{ | ||
"method": c.Request.Method, | ||
"path": c.Request.URL.Path, | ||
}).Info("Incoming request") | ||
|
||
c.Next() | ||
|
||
// Log outgoing response | ||
logrus.WithField("status", c.Writer.Status()).Info("Outgoing response") | ||
} | ||
} | ||
|
||
func Recovery() gin.HandlerFunc { | ||
return func(c *gin.Context) { | ||
defer func() { | ||
if err := recover(); err != nil { | ||
// Log panic | ||
logrus.WithField("error", err).Error("Panic recovered") | ||
|
||
// Abort request | ||
c.AbortWithStatus(500) | ||
} | ||
}() | ||
c.Next() | ||
} | ||
} |