Skip to content
Open
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
55 changes: 55 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: CI

on:
push:
branches: [ main, master ]
pull_request:
branches: [ main, master ]

env:
REGISTRY: "cr.selcloud.ru/microservices"
IMAGE_NAME: "auth-service"
CONTAINER_NAME: "auth-service-container"

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

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 }} $REGISTRY

- 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 .

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

steps:
- name: Deploy to Selectel Cloud via SSH action
uses: appleboy/[email protected]
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_KEY }}
envs: IMAGE_NAME,REGISTRY,GITHUB_SHA,CONTAINER_NAME
script: |
TAG_NAME=$(echo $GITHUB_SHA | head -c7)

docker login -u ${{ secrets.REGISTRY_USERNAME }} -p ${{ secrets.REGISTRY_PASSWORD }} $REGISTRY

docker stop $CONTAINER_NAME

docker rm $CONTAINER_NAME

docker run -d -p 50051:50051 --name $CONTAINER_NAME -t $REGISTRY/$IMAGE_NAME:$TAG_NAME
67 changes: 0 additions & 67 deletions .github/workflows/go.yaml

This file was deleted.

14 changes: 14 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM golang:1.20-alpine3.17 AS builder

COPY . /auth
WORKDIR /auth

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

FROM alpine:latest

WORKDIR /root/
COPY --from=builder /auth/bin/main .

CMD ["./main"]