test: configure terraform based on env and push to dockerhub #1
Workflow file for this run
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
# The following secrets are required from the repository's settings: | |
# https://github.com/your_username/itu-minitwit-ci/settings/secrets/actions | |
# DOCKER_USERNAME | |
# DOCKER_PASSWORD | |
# SSH_USER = root | |
# SSH_KEY_PRE | |
# SSH_HOST_PRE | |
# DB_CONNECTIONSTRING_STAGING | |
name: Deploy #shoutout to the exercises session | |
on: | |
push: | |
branches: | |
- 'feature/grafana-server-terraform' | |
workflow_dispatch: | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v2 | |
- name: Login to Docker Hub | |
uses: docker/login-action@v1 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v1 | |
- name: Build and push csharptwit-production | |
uses: docker/build-push-action@v2 | |
with: | |
context: ./csharp-minitwit | |
file: ./csharp-minitwit/Dockerfile | |
push: true | |
tags: ${{ secrets.DOCKER_USERNAME }}/csharptwit-production:latest | |
cache-from: type=registry,ref=${{ secrets.DOCKER_USERNAME }}/csharptwit-staging:webbuildcache | |
cache-to: type=registry,ref=${{ secrets.DOCKER_USERNAME }}/csharptwit-staging:webbuildcache,mode=max | |
build-args: ENVIRONMENT=Staging | |
- name: Configure SSH | |
run: | | |
mkdir -p ~/.ssh/ | |
echo "$SSH_KEY" > ~/.ssh/staging_key | |
chmod 600 ~/.ssh/staging_key | |
env: | |
SSH_KEY: ${{ secrets.SSH_KEY_PRE }} | |
- name: Copy files to server | |
# Updating stack files on remote server from the infrastructure/stack folder | |
run: > | |
scp -i ~/.ssh/staging_key -o StrictHostKeyChecking=no | |
./infrastructure/stack/* $SSH_USER@$SSH_HOST:~/ | |
env: | |
SSH_USER: ${{ secrets.SSH_USER }} | |
SSH_HOST: ${{ secrets.SSH_HOST }} | |
- name: Deploy to server | |
# Pulls minitwit image from Docker Hub and updates the swarm | |
run: | | |
ssh -i ~/.ssh/staging_key -o StrictHostKeyChecking=no $SSH_USER@$SSH_HOST << 'EOF' | |
export ConnectionStrings__DefaultConnection=${{ secrets.DB_CONNECTIONSTRING_PRODUCTION }} | |
export DOCKER_USERNAME=${{ secrets.DOCKER_USERNAME }} | |
export STAGE=production | |
echo "Deploying stack 'minitwit'..." | |
docker stack deploy minitwit -c minitwit_stack.yml | |
EOF | |
env: | |
SSH_USER: ${{ secrets.SSH_USER }} | |
SSH_HOST: ${{ secrets.SSH_HOST }} |