Skip to content

2024 updates

2024 updates #100

Workflow file for this run

name: Backend - build and deploy
on:
push:
branches:
- main
paths:
- "server/**" # limit workflow only to changes in backend folder
- ".github/workflows/server-cd.yml"
pull_request:
branches:
- main
paths:
- "server/**"
- ".github/workflows/server-cd.yml"
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: checkout current repository
uses: actions/checkout@v4
- name: set up Java 21
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'temurin'
- name: build application jar
uses: gradle/actions/setup-gradle@v3
with:
gradle-version: wrapper
arguments: build
build-root-directory: server
- name: create server artifact from jar
# if: github.ref == 'refs/heads/main'
uses: actions/upload-artifact@v4
with:
name: server
path: server/build
publish:
needs: build
# if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
steps:
- name: set up WARP (workaround for IPv6 on GitHub Actions)
uses: fscarmen/warp-on-actions@v1.1
with:
stack: ipv6
- name: checkout current repository
uses: actions/checkout@v4
- name: download server artifact
uses: actions/download-artifact@v4
with:
name: server
path: server/build
- name: set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: log in to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: build and publish server Docker image
uses: docker/build-push-action@v6
with:
context: server
file: server/docker/Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: stenal/baltic-stock-server:latest
- name: setup SSH
shell: bash
run: |
eval `ssh-agent -s`
mkdir -p /home/runner/.ssh/
touch /home/runner/.ssh/id_rsa
echo -e "${{secrets.SSH_KEY}}" > /home/runner/.ssh/id_rsa
chmod 700 /home/runner/.ssh/id_rsa
ssh-keyscan -t rsa,dsa,ecdsa,ed25519 ${{ secrets.SSH_HOST }} >> /home/runner/.ssh/known_hosts
- name: run Ansible deployment playbook
shell: bash
run: |
cd ansible
ansible-playbook -vv --private-key /home/runner/.ssh/id_rsa -u ${{secrets.SSH_USER}} -i ${{ secrets.SSH_HOST }}, main.yml