Merge pull request #4 from markgenuine/hw4 #11
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
name: CI | |
on: | |
push: | |
branches: [ main ] | |
pull_request: | |
branches: [ main ] | |
env: | |
REGISTRY: "cr.selcloud.ru/tests" | |
IMAGE_NAME: "auth_server" | |
CONTAINER_NAME: "auth-server-container" | |
jobs: | |
image_build_and_push: | |
runs-on: ubuntu-20.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-20.04 | |
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 }} | |
password: ${{ secrets.SSH_PASSWORD }} | |
#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 |