101 lines
3.2 KiB
YAML
101 lines
3.2 KiB
YAML
name: Build and push timelimit-server-ui image
|
|
|
|
on:
|
|
schedule:
|
|
- cron: "0 0 */3 * *" # every 72 hours
|
|
workflow_dispatch:
|
|
|
|
jobs:
|
|
check:
|
|
runs-on: ubuntu-latest
|
|
outputs:
|
|
exists: ${{ steps.exists.outputs.exists }}
|
|
sha: ${{ steps.sha.outputs.sha }}
|
|
steps:
|
|
# Get latest timelimit-server-ui commit SHA
|
|
- name: Get timelimit-server-ui commit SHA
|
|
id: sha
|
|
run: |
|
|
SHA=$(git ls-remote https://gitea.furb.it/${{ vars.FRONTEND_PATH }}.git refs/heads/${{ vars.FRONTEND_BRANCH }} | cut -f1)
|
|
echo "sha=$SHA" >> $GITEA_OUTPUT
|
|
|
|
# Try to read timelimit-server-ui SHA from latest image label
|
|
- name: Check if image with timelimit-server-ui SHA exists
|
|
id: exists
|
|
run: |
|
|
SHA="${{ steps.sha.outputs.sha }}"
|
|
|
|
STATUS=$(curl -s -o /dev/null -w "%{http_code}" \
|
|
-u "${{ secrets.USERNAME }}:${{ secrets.ACCESS_TOKEN }}" \
|
|
-H "Accept: application/vnd.docker.distribution.manifest.v2+json" \
|
|
https://gitea.furb.it/v2/${{ vars.FRONTEND_IMAGE }}/manifests/$SHA)
|
|
|
|
if [ "$STATUS" = "200" ]; then
|
|
echo "exists=true" >> $GITEA_OUTPUT
|
|
else
|
|
echo "exists=false" >> $GITEA_OUTPUT
|
|
fi
|
|
|
|
build:
|
|
runs-on: ubuntu-latest
|
|
needs: check
|
|
if: needs.check.outputs.exists == 'false'
|
|
steps:
|
|
# Checkout THIS repository (Dockerfile lives here)
|
|
- name: Checkout current repository
|
|
uses: actions/checkout@v4
|
|
|
|
# Checkout timelimit-server-ui repository for build
|
|
- name: Checkout timelimit-server-ui repository
|
|
uses: actions/checkout@v4
|
|
with:
|
|
repository: ${{ vars.FRONTEND_PATH }}.git
|
|
ref: ${{ needs.check.outputs.sha }}
|
|
path: timelimit-server-ui
|
|
token: ${{ secrets.ACCESS_TOKEN }}
|
|
|
|
# Set up Node.js
|
|
- name: Set up Node.js
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: 20
|
|
cache: npm
|
|
cache-dependency-path: timelimit-server-ui/package-lock.json
|
|
|
|
- name: npm install
|
|
working-directory: timelimit-server-ui
|
|
run: npm install
|
|
|
|
- name: npm run build
|
|
working-directory: timelimit-server-ui
|
|
run: npm run build
|
|
|
|
# Prepare Docker build context
|
|
- name: Prepare Docker context
|
|
run: |
|
|
rm -rf dist
|
|
cp -r timelimit-server-ui/dist ./dist
|
|
|
|
# Login to registry (needed to inspect latest image)
|
|
- name: Docker login
|
|
run: |
|
|
echo "${{ secrets.ACCESS_TOKEN }}" | docker login gitea.furb.it \
|
|
-u "${{ secrets.USERNAME }}" \
|
|
--password-stdin
|
|
|
|
# Build image with commit-SHA tag and label
|
|
- name: Build Docker image
|
|
run: |
|
|
docker build \
|
|
-f Dockerfile-ui \
|
|
--label timelimit-server-ui.sha=${{ needs.check.outputs.sha }} \
|
|
-t gitea.furb.it/${{ vars.FRONTEND_IMAGE }}:${{ needs.check.outputs.sha }} \
|
|
-t gitea.furb.it/${{ vars.FRONTEND_IMAGE }}:latest \
|
|
.
|
|
|
|
# Push images
|
|
- name: Push Docker images
|
|
run: |
|
|
docker push gitea.furb.it/${{ vars.FRONTEND_IMAGE }}:${{ needs.check.outputs.sha }}
|
|
docker push gitea.furb.it/${{ vars.FRONTEND_IMAGE }}:latest
|