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

on:
workflow_dispatch:
inputs:
TAG:
required: true
description: 'Docker container tag'
default: staging

env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}

jobs:
build_an_push:
name: Build and Push a docker image
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Set env
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1

- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1

- name: Build, tag, and push image to Amazon ECR
id: build-image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: sidecache
IMAGE_TAG: ${{ github.event.inputs.TAG || env.RELEASE_VERSION }}
run: |
# Build a docker container and push it to ECR
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG --build-arg release_version=${IMAGE_TAG} .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
echo "::set-output name=image::$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG"
13 changes: 11 additions & 2 deletions pkg/lock/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@ package lock

import (
"errors"
"sync"
"time"

"github.com/google/uuid"
"github.com/zeriontech/sidecache/pkg/cache"
"time"
)

type RedisLock struct {
redis *cache.RedisRepository
redis *cache.RedisRepository
values map[string]string
mutex sync.Mutex
}

const UnlockScript = `
Expand All @@ -25,12 +28,18 @@ func NewRedisLock(redis *cache.RedisRepository) *RedisLock {
}

func (lock *RedisLock) Acquire(key string, ttl time.Duration) error {
lock.mutex.Lock()
defer lock.mutex.Unlock()

val := uuid.NewString()
lock.values[key] = val
return lock.redis.SetNX(key, val, ttl)
}

func (lock *RedisLock) Release(key string) error {
lock.mutex.Lock()
defer lock.mutex.Unlock()

val, ok := lock.values[key]
if !ok {
return errors.New("unknown key")
Expand Down