diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index f553c45..18c3118 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -1,6 +1,67 @@ +#name: CI +##Check your CI/CD configuration with the following command: +## docker-compose -f internal/config/docker-compose.yaml config +#on: +# push: +# branches: [ main, master ] +# pull_request: +# branches: [ main, master ] +# +#env: +# REGISTRY: "cr.selcloud.ru/andyregistry" +# IMAGE_NAME: "crud-server" +# CONTAINER_NAME: "crud-server-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 }} $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 -f Dockerfile . +# +# deploy-image: +# runs-on: ubuntu-latest +# needs: image-build-and-push +# +# steps: +# - name: Deploy to Selectel Cloud via SSH action +# uses: appleboy/ssh-action@v1.0.0 +# with: +# host: ${{ secrets.SERVER_HOST }} +# username: ${{ secrets.SSH_USERNAME }} +# key: ${{ secrets.SSHKEY }} +# 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 }} $REGISTRY +# +# # 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 + name: CI -#Check your CI/CD configuration with the following command: -# docker-compose -f internal/config/docker-compose.yaml config + on: push: branches: [ main, master ] @@ -8,54 +69,55 @@ on: branches: [ main, master ] env: - REGISTRY: "cr.selcloud.ru/andyregistry" - IMAGE_NAME: "crud-server" - CONTAINER_NAME: "crud-server-container" + REGISTRY: "cr.selcloud.ru/microservices" + IMAGE_NAME: "chat-server" + CONTAINER_NAME: "chat-server-container" jobs: image-build-and-push: - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 steps: - name: Checkout master - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 + uses: docker/setup-buildx-action@v3 - 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) + TAG=$(echo $GITHUB_SHA | head -c7) docker buildx create --use - docker buildx build --no-cache --push --tag $REGISTRY/$IMAGE_NAME:$TAG_NAME -f Dockerfile . + docker buildx build --no-cache --push --tag $REGISTRY/$IMAGE_NAME:$TAG --build-arg="ENV=stage" --build-arg="CONFIG=stage.env" . deploy-image: - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 needs: image-build-and-push steps: - name: Deploy to Selectel Cloud via SSH action - uses: appleboy/ssh-action@v1.0.0 + uses: appleboy/ssh-action@v1.0.3 with: - host: ${{ secrets.SERVER_HOST }} + host: ${{ secrets.SSH_HOST }} username: ${{ secrets.SSH_USERNAME }} - key: ${{ secrets.SSHKEY }} + key: ${{ secrets.SSH_KEY }} + passphrase: ${{ secrets.SSH_KEY_PASSPHRASE }} 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 }} $REGISTRY - + # 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 \ No newline at end of file + docker run -d -p 50001:50001 --name $CONTAINER_NAME -t $REGISTRY/$IMAGE_NAME:$TAG_NAME \ No newline at end of file diff --git a/.github/workflows/go.yaml b/.github/workflows/go.yaml index 1f992f8..974b94b 100644 --- a/.github/workflows/go.yaml +++ b/.github/workflows/go.yaml @@ -1,22 +1,19 @@ name: Go -#Check your CI/CD configuration with the following command: -# docker-compose -f internal/config/docker-compose.yaml config - on: push: - branches: [ main ] + branches: [ main, master ] pull_request: - branches: [ main ] + branches: [ main, master ] jobs: build-and-test: - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Set up Go - uses: actions/setup-go@v4 + uses: actions/setup-go@v5 with: go-version: '1.22' cache-dependency-path: go.sum @@ -29,20 +26,20 @@ jobs: linter: name: lint - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@v3 - - uses: actions/setup-go@v4 + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 with: go-version: '1.22' cache: false - name: golangci-lint - uses: golangci/golangci-lint-action@v3 + uses: golangci/golangci-lint-action@v4 with: # Require: The version of golangci-lint to use. # When `install-mode` is `binary` (default) the value can be v1.2 or v1.2.3 or `latest` to use the latest version. # When `install-mode` is `goinstall` the value can be v1.2.3, `latest`, or the hash of a commit. - version: v1.56.2 + version: v1.56 # Optional: working directory, useful for monorepos # working-directory: somedir @@ -67,6 +64,4 @@ jobs: # skip-build-cache: true # Optional: The mode to install golangci-lint. It can be 'binary' or 'goinstall'. - # install-mode: "goinstall" - - + # install-mode: "goinstall" \ No newline at end of file diff --git a/.gitignore b/.gitignore index f3a1ebf..6a56a46 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,37 @@ -.idea -/bin/ \ No newline at end of file +#.idea +#/bin/ + + +# If you prefer the allow list template instead of the deny list, see community template: +# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore +# +# Binaries for programs and plugins +*.exe +*.exe~ +*.dll +*.so +*.dylib + +# Test binary, built with `go test -c` +*.test + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out + +# Dependency directories (remove the comment below to include it) +# vendor/ + +# Go workspace file +go.work + +# Directory with binary files +/bin/ + +# Tests coverage +coverage.* + +# Certificates and private keys +/tls/ + +# Access token for testing +.access_token \ No newline at end of file diff --git a/.golangci.pipeline.yaml b/.golangci.pipeline.yaml index 341faf5..a78e89f 100644 --- a/.golangci.pipeline.yaml +++ b/.golangci.pipeline.yaml @@ -1,4 +1,4 @@ -# More info on api_config here: https://golangci-lint.run/usage/configuration/#config-file +# More info on config here: https://golangci-lint.run/usage/configuration/#config-file run: concurrency: 8 timeout: 10m @@ -27,7 +27,7 @@ linters-settings: goconst: min-len: 2 min-occurrences: 2 - + linters: disable-all: true enable: @@ -49,4 +49,4 @@ issues: - G104 - exported func .* returns unexported type .*, which can be annoying to use - should have a package comment - - don't use an underscore in package name + - don't use an underscore in package name \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..a9d7db9 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,10 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +# GitHub Copilot persisted chat sessions +/copilot/chatSessions diff --git a/.idea/chat-server.iml b/.idea/chat-server.iml new file mode 100644 index 0000000..5d81a31 --- /dev/null +++ b/.idea/chat-server.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/dataSources.xml b/.idea/dataSources.xml new file mode 100644 index 0000000..d6d7437 --- /dev/null +++ b/.idea/dataSources.xml @@ -0,0 +1,12 @@ + + + + + postgresql + true + org.postgresql.Driver + jdbc:postgresql://localhost:54321/chats + $ProjectFileDir$ + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..1291854 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/sqldialects.xml b/.idea/sqldialects.xml new file mode 100644 index 0000000..6df4889 --- /dev/null +++ b/.idea/sqldialects.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file