Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/dev' into fix/create-job-post
Browse files Browse the repository at this point in the history
  • Loading branch information
uloamaka committed Aug 8, 2024
2 parents 5f2db1b + 7da03d9 commit 2171b42
Show file tree
Hide file tree
Showing 12 changed files with 261 additions and 117 deletions.
49 changes: 49 additions & 0 deletions .github/workflows/development.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,44 @@ on:
- dev

jobs:
build_docker_image:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Build Docker image
run: docker build -t golang_dev .
- name: Save and compress Docker image
run: docker save golang_dev | gzip > golang_dev.tar.gz
- name: Upload Docker image
uses: actions/upload-artifact@v4
with:
name: golang_dev
path: golang_dev.tar.gz

upload_docker_image:
runs-on: ubuntu-latest
needs: build
if: github.event.repository.fork == false
environment:
name: "development"
url: ${{ vars.URL }}
steps:
- name: Download Docker image
uses: actions/download-artifact@v4
with:
name: golang_dev
path: .

- name: Copy image to server
uses: appleboy/scp-action@master
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
password: ${{ secrets.SSH_PASSWORD }}
source: golang_dev.tar.gz
target: "/tmp"

build_and_test:
runs-on: ubuntu-latest
environment: development
Expand Down Expand Up @@ -114,3 +152,14 @@ jobs:
MAIL_PASSWORD=${{ secrets.MAIL_PASSWORD }} \
MAIL_PORT=${{ secrets.MAIL_PORT }} \
MIGRATE=true
- name: Deploy on server
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
password: ${{ secrets.PASSWORD }}
script: |
gunzip -c /tmp/golang_dev.tar.gz | docker load
rm -f /tmp/golang_dev.tar.gz
cd ~/deployments/development
docker compose up -d
49 changes: 49 additions & 0 deletions .github/workflows/production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,44 @@ on:
- main

jobs:
build_docker_image:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Build Docker image
run: docker build -t golang_prod .
- name: Save and compress Docker image
run: docker save golang_prod | gzip > golang_prod.tar.gz
- name: Upload Docker image
uses: actions/upload-artifact@v4
with:
name: golang_prod
path: golang_prod.tar.gz

upload_docker_image:
runs-on: ubuntu-latest
needs: build
if: github.event.repository.fork == false
environment:
name: "development"
url: ${{ vars.URL }}
steps:
- name: Download Docker image
uses: actions/download-artifact@v4
with:
name: golang_prod
path: .

- name: Copy image to server
uses: appleboy/scp-action@master
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
password: ${{ secrets.SSH_PASSWORD }}
source: golang_prod.tar.gz
target: "/tmp"

build_and_test:
runs-on: ubuntu-latest
environment: production
Expand Down Expand Up @@ -109,3 +147,14 @@ jobs:
MAIL_PASSWORD=${{ secrets.MAIL_PASSWORD }} \
MAIL_PORT=${{ secrets.MAIL_PORT }} \
MIGRATE=true
- name: Deploy on server
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
password: ${{ secrets.PASSWORD }}
script: |
gunzip -c /tmp/golang_prod.tar.gz | docker load
rm -f /tmp/golang_prod.tar.gz
cd ~/deployments/production
docker compose up -d
49 changes: 49 additions & 0 deletions .github/workflows/staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,44 @@ on:
- staging

jobs:
build_docker_image:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Build Docker image
run: docker build -t golang_staging .
- name: Save and compress Docker image
run: docker save golang_staging | gzip > golang_staging.tar.gz
- name: Upload Docker image
uses: actions/upload-artifact@v4
with:
name: golang_staging
path: golang_staging.tar.gz

upload_docker_image:
runs-on: ubuntu-latest
needs: build
if: github.event.repository.fork == false
environment:
name: "development"
url: ${{ vars.URL }}
steps:
- name: Download Docker image
uses: actions/download-artifact@v4
with:
name: golang_staging
path: .

- name: Copy image to server
uses: appleboy/scp-action@master
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
password: ${{ secrets.SSH_PASSWORD }}
source: golang_staging.tar.gz
target: "/tmp"

build_and_test:
runs-on: ubuntu-latest
environment: staging
Expand Down Expand Up @@ -109,3 +147,14 @@ jobs:
MAIL_PASSWORD=${{ secrets.MAIL_PASSWORD }} \
MAIL_PORT=${{ secrets.MAIL_PORT }} \
MIGRATE=true
- name: Deploy on server
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
password: ${{ secrets.PASSWORD }}
script: |
gunzip -c /tmp/golang_staging.tar.gz | docker load
rm -f /tmp/golang_staging.tar.gz
cd ~/deployments/staging
docker compose up -d
16 changes: 8 additions & 8 deletions docker-compose-development.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ services:
env_file:
- app.env

# nginx:
# image: nginx:latest
# ports:
# - "5000:80"
# depends_on:
# - backend
# volumes:
# - ./nginx.conf:/etc/nginx/nginx.conf
nginx:
image: nginx:latest
ports:
- "8000:80"
depends_on:
- backend
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf

volumes:
db_data:
16 changes: 8 additions & 8 deletions docker-compose-production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ services:
env_file:
- app.env

# nginx:
# image: nginx:latest
# ports:
# - "5000:80"
# depends_on:
# - backend
# volumes:
# - ./nginx.conf:/etc/nginx/nginx.conf
nginx:
image: nginx:latest
ports:
- "8002:80"
depends_on:
- backend
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf

volumes:
db_data:
16 changes: 8 additions & 8 deletions docker-compose-staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ services:
env_file:
- app.env

# nginx:
# image: nginx:latest
# ports:
# - "5000:80"
# depends_on:
# - backend
# volumes:
# - ./nginx.conf:/etc/nginx/nginx.conf
nginx:
image: nginx:latest
ports:
- "8001:80"
depends_on:
- backend
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf

volumes:
db_data:
27 changes: 27 additions & 0 deletions nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
worker_processes 1;

events { worker_connections 1024; }

http {
upstream backend {
least_conn;
server backend:8000;
}

server {
listen 80;

server_name _;

location / {
proxy_pass http://backend;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection keep-alive;
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
}
16 changes: 13 additions & 3 deletions pkg/controller/user/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/hngprojects/hng_boilerplate_golang_web/external/request"
"github.com/hngprojects/hng_boilerplate_golang_web/internal/models"
"github.com/hngprojects/hng_boilerplate_golang_web/pkg/middleware"
"github.com/hngprojects/hng_boilerplate_golang_web/pkg/repository/storage"
service "github.com/hngprojects/hng_boilerplate_golang_web/services/user"
"github.com/hngprojects/hng_boilerplate_golang_web/utility"
Expand Down Expand Up @@ -53,9 +54,18 @@ func (base *Controller) GetAUser(c *gin.Context) {

func (base *Controller) GetAUserOrganisation(c *gin.Context) {

var (
userID = c.Param("user_id")
)
userId, err := middleware.GetUserClaims(c, base.Db.Postgresql, "user_id")
if err != nil {
if err.Error() == "user claims not found" {
rd := utility.BuildErrorResponse(http.StatusBadRequest, "error", err.Error(), "failed to retrieve organisations", nil)
c.JSON(http.StatusNotFound, rd)
return
}
rd := utility.BuildErrorResponse(http.StatusInternalServerError, "error", err.Error(), "failed to retrieve organisations", nil)
c.JSON(http.StatusInternalServerError, rd)
return
}
userID := userId.(string)

userData, code, err := service.GetAUserOrganisation(userID, base.Db.Postgresql, c)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/router/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func User(r *gin.Engine, ApiVersion string, validator *validator.Validate, db *s
userUrl.GET("/users/:user_id", user.GetAUser)
userUrl.DELETE("/users/:user_id", user.DeleteAUser)
userUrl.PUT("/users/:user_id", user.UpdateAUser)
userUrl.GET("/users/:user_id/organizations", user.GetAUserOrganisation)
userUrl.GET("/organizations", user.GetAUserOrganisation)
userUrl.PUT("/users/:user_id/roles/:role_id", user.AssignRoleToUser)
userUrl.PUT("/users/:user_id/regions", user.UpdateUserRegion)
userUrl.GET("/users/:user_id/regions", user.GetUserRegion)
Expand Down
Loading

0 comments on commit 2171b42

Please sign in to comment.