Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added github actions #1

Merged
merged 1 commit into from
Mar 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: CI

on:
push:
branches: [ main, master ]

env:
REGISTRY: "terdenan"
IMAGE_NAME: "msc_auth"
CONTAINER_NAME: "msc_auth_container"

jobs:
image-build-and-push:
runs-on: ubuntu-latest

steps:
- name: Checkout master
uses: actions/checkout@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Login to Docker Registry
run: docker login -u ${{ secrets.REGISTRY_USERNAME }} -p ${{ secrets.REGISTRY_PASSWORD }}

- name: Build and Push Docker Image
run: |
TAG_NAME=$(echo $GITHUB_SHA | head -c7)
docker buildx create --use
docker buildx build --no-cache --push --tag $REGISTRY/$IMAGE_NAME:$TAG_NAME -f Dockerfile

deploy-image:
runs-on: ubuntu-latest
needs: image-build-and-push

steps:
- name: Deploy to server
uses: appleboy/ssh-action@v1.0.0
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_KEY }}
envs: IMAGE_NAME,REGISTRY,GITHUB_SHA,CONTAINER_NAME
script: |
# Set up variables
TAG_NAME=$(echo $GITHUB_SHA | head -c7)

# Login into Selectel Registry
docker login -u ${{ secrets.REGISTRY_USERNAME }} -p ${{ secrets.REGISTRY_PASSWORD }}

# Stop running container
docker stop $CONTAINER_NAME

# Remove old container
docker rm $CONTAINER_NAME

# Run a new container from a new image
docker run -d -p 50051:50051 --name $CONTAINER_NAME -t $REGISTRY/$IMAGE_NAME:$TAG_NAME
22 changes: 22 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
################################
# STEP 1 build executable binary
################################

FROM golang:1.20.3-alpine AS builder

COPY . /app/src/
WORKDIR /app/src/

RUN go mod download
RUN go build -o ./bin/auth_server cmd/grpc_server/main.go

############################
# STEP 2 build a small image
############################

FROM alpine:latest

WORKDIR /root/
COPY --from=builder /app/src/bin/auth_server .

CMD [ "./auth_server" ]
3 changes: 2 additions & 1 deletion internal/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@
}

func (a *App) initConfig(_ context.Context) error {
return config.Load(".env")
config.Load(".env")

Check failure on line 53 in internal/app/app.go

View workflow job for this annotation

GitHub Actions / lint

Error return value of `config.Load` is not checked (errcheck)
return nil
}

func (a *App) initServiceProvider(_ context.Context) error {
Expand Down
Loading