improve message #26
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: Server Deployment | |
on: | |
push: | |
branches: | |
- main | |
paths: | |
- 'server/**' | |
jobs: | |
deploying-server: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v2 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v1 | |
- name: Create .env file | |
run: | | |
echo "POSTGRES_USER=${{ secrets.POSTGRES_USER }}" > ./server/.env | |
echo "POSTGRES_PASSWORD=${{ secrets.POSTGRES_PASSWORD }}" >> ./server/.env | |
echo "DATABASE_URL=${{ secrets.DATABASE_URL }}" >> ./server/.env | |
echo "DATABASE_MIGRATION_URL=${{ secrets.DATABASE_MIGRATION_URL }}" >> ./server/.env | |
echo "PORT=${{ secrets.PORT }}" >> ./server/.env | |
echo "ENVIRONMENT=${{ secrets.ENVIRONMENT }}" >> ./server/.env | |
echo "REDIS_URL=${{ secrets.REDIS_URL }}" >> ./server/.env | |
echo "WHITELIST_DOMAIN=${{ secrets.WHITELIST_DOMAIN }}" >> ./server/.env | |
env: | |
POSTGRES_USER: ${{ secrets.POSTGRES_USER }} | |
POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }} | |
DATABASE_URL: ${{ secrets.DATABASE_URL }} | |
DATABASE_MIGRATION_URL: ${{ secrets.DATABASE_MIGRATION_URL }} | |
PORT: ${{ secrets.PORT }} | |
ENVIRONMENT: ${{ secrets.ENVIRONMENT }} | |
REDIS_URL: ${{ secrets.REDIS_URL }} | |
WHITELIST_DOMAIN: ${{ secrets.WHITELIST_DOMAIN }} | |
- name: Login to Docker Hub | |
uses: docker/login-action@v1 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Build and push Docker image | |
uses: docker/build-push-action@v2 | |
with: | |
context: . | |
file: ./server/Dockerfile # Specify the path to your Dockerfile | |
platforms: linux/amd64,linux/arm64 | |
push: true | |
tags: | | |
slackingdjaeger/jagadis-server:latest | |
slackingdjaeger/jagadis-server:${{ github.sha }} | |
- name: Set up SSH | |
run: | | |
mkdir -p ~/.ssh | |
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa | |
chmod 600 ~/.ssh/id_rsa | |
echo "${{ secrets.SSH_PRIVATE_KEY }}" >> ~/.ssh/authorized_keys | |
chmod 700 ~/.ssh/authorized_keys | |
ssh-keyscan -t rsa ${{ secrets.SSH_HOST }} >> ~/.ssh/known_hosts | |
- name: Deploy server | |
run: | | |
ssh ${{ secrets.SSH_USERNAME }}@${{ secrets.SSH_HOST }} "mkdir -p jagadis" | |
scp ./server/.env ${{ secrets.SSH_USERNAME }}@${{ secrets.SSH_HOST }}:jagadis/.env | |
scp ./server/docker-compose.yml ${{ secrets.SSH_USERNAME }}@${{ secrets.SSH_HOST }}:jagadis/docker-compose.yml | |
ssh ${{ secrets.SSH_USERNAME }}@${{ secrets.SSH_HOST }} "cd jagadis && sudo docker compose up -d" | |
- name: Set up Go | |
uses: actions/setup-go@v2 | |
with: | |
go-version: 1.21 | |
cache: 'go' | |
- name: Migrate Database | |
run: cd server/src/db && go run migrate.go |