Deploy Auth Service #16
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: Deploy Auth Service | |
on: | |
workflow_dispatch: | |
inputs: | |
deploy: | |
description: 'Deploy the service' | |
required: true | |
default: 'false' | |
env: | |
DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }} | |
DOCKER_HUB_PASSWORD: ${{ secrets.DOCKER_HUB_PASSWORD }} | |
KUBE_CONFIG: ${{ secrets.KUBE_CONFIG }} | |
NAMESPACE: ${{ secrets.NAMESPACE }} | |
IMAGE: andreq21/auth:${{ github.sha }} | |
POSTGRES_HOST: ${{ vars.POSTGRES_HOST }} | |
POSTGRES_PORT: ${{ vars.POSTGRES_PORT }} | |
POSTGRES_USER: ${{ vars.POSTGRES_USER }} | |
POSTGRES_PASSWORD: ${{ vars.POSTGRES_PASSWORD }} | |
POSTGRES_DB: ${{ vars.POSTGRES_DB }} | |
HTTP_SERVER_HOST: ${{ vars.HTTP_SERVER_HOST }} | |
HTTP_SERVER_PORT: ${{ vars.HTTP_SERVER_PORT }} | |
HTTP_SERVER_TIMEOUT: ${{ vars.HTTP_SERVER_TIMEOUT }} | |
GRPC_SERVER_HOST: ${{ vars.GRPC_SERVER_HOST }} | |
GRPC_SERVER_PORT: ${{ vars.GRPC_SERVER_PORT }} | |
GRPC_SERVER_TIMEOUT: ${{ vars.GRPC_SERVER_TIMEOUT }} | |
JWT_ACCESS_SECRET: ${{ vars.JWT_ACCESS_SECRET }} | |
JWT_ACCESS_DURATION: ${{ vars.JWT_ACCESS_DURATION }} | |
JWT_REFRESH_SECRET: ${{ vars.JWT_REFRESH_SECRET }} | |
JWT_REFRESH_DURATION: ${{ vars.JWT_REFRESH_DURATION }} | |
jobs: | |
lint: | |
runs-on: ubuntu-latest | |
environment: auth-production | |
if: github.event_name == 'workflow_dispatch' && github.event.inputs.deploy == 'true' | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Set up Go | |
uses: actions/setup-go@v4 | |
with: | |
go-version: 1.22.4 | |
- name: Run linters | |
run: | | |
go install github.com/golangci/golangci-lint/cmd/[email protected] | |
golangci-lint run ./service/auth/... --config ./.golangci.pipeline.yaml | |
build: | |
runs-on: ubuntu-latest | |
environment: auth-production | |
needs: lint | |
if: github.event_name == 'workflow_dispatch' && github.event.inputs.deploy == 'true' | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Build Docker image | |
run: | | |
docker build -t $IMAGE -f ./service/auth/Dockerfile . | |
- name: Login to Docker Hub | |
run: | | |
echo $DOCKER_HUB_PASSWORD | docker login -u $DOCKER_HUB_USERNAME --password-stdin | |
- name: Push Docker image to Docker Hub | |
run: | | |
docker push $IMAGE | |
deploy: | |
runs-on: ubuntu-latest | |
environment: auth-production | |
needs: build | |
if: github.event_name == 'workflow_dispatch' && github.event.inputs.deploy == 'true' | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Install dependencies | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y gettext | |
- name: Create .env file | |
run: | | |
echo "POSTGRES_HOST=$POSTGRES_HOST" >> .env | |
echo "POSTGRES_PORT=$POSTGRES_PORT" >> .env | |
echo "POSTGRES_USER=$POSTGRES_USER" >> .env | |
echo "POSTGRES_PASSWORD=$POSTGRES_PASSWORD" >> .env | |
echo "POSTGRES_DB=$POSTGRES_DB" >> .env | |
echo "HTTP_SERVER_HOST=$HTTP_SERVER_HOST" >> .env | |
echo "HTTP_SERVER_PORT=$HTTP_SERVER_PORT" >> .env | |
echo "HTTP_SERVER_TIMEOUT=$HTTP_SERVER_TIMEOUT" >> .env | |
echo "GRPC_SERVER_HOST=$GRPC_SERVER_HOST" >> .env | |
echo "GRPC_SERVER_PORT=$GRPC_SERVER_PORT" >> .env | |
echo "GRPC_SERVER_TIMEOUT=$GRPC_SERVER_TIMEOUT" >> .env | |
echo "JWT_ACCESS_SECRET=$JWT_ACCESS_SECRET" >> .env | |
echo "JWT_ACCESS_DURATION=$JWT_ACCESS_DURATION" >> .env | |
echo "JWT_REFRESH_SECRET=$JWT_REFRESH_SECRET" >> .env | |
echo "JWT_REFRESH_DURATION=$JWT_REFRESH_DURATION" >> .env | |
- name: Set up kubectl | |
run: | | |
mkdir -p $HOME/.kube | |
echo "$KUBE_CONFIG" | base64 --decode > $HOME/.kube/config | |
- name: Substitute environment variables in configmap | |
run: | | |
export $(cat .env | xargs) | |
envsubst < deploy/helm/auth/templates/configmap.yaml > ./configmap.yaml | |
mv ./configmap.yaml deploy/helm/auth/templates/configmap.yaml | |
- name: Deploy to Kubernetes | |
run: | | |
helm upgrade --install auth ./deploy/helm/auth --namespace=$NAMESPACE --set app.image.tag=$IMAGE |