Automate build of timelimit-server-ui docker image
This commit is contained in:
@@ -0,0 +1,101 @@
|
||||
name: Build and push timelimit-server-ui image
|
||||
|
||||
on:
|
||||
schedule:
|
||||
- cron: "0 0 */3 * *" # every 72 hours
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
# Checkout THIS repository (Dockerfile lives here)
|
||||
- name: Checkout current repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
# 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
|
||||
|
||||
# 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
|
||||
|
||||
# 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
|
||||
|
||||
# Exit early if unchanged
|
||||
- name: Skip build if image already exists
|
||||
run: |
|
||||
if [ "${{ steps.exists.outputs.exists }}" = "true" ]; then
|
||||
echo "Image for this timelimit-server-ui commit already exists. Skipping build."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Checkout timelimit-server-ui repository for build
|
||||
- name: Checkout timelimit-server-ui repository
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
repository: ${{ vars.FRONTEND_PATH }}.git
|
||||
ref: ${{ steps.sha.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
|
||||
|
||||
# Build image with commit-SHA tag and label
|
||||
- name: Build Docker image
|
||||
run: |
|
||||
docker build \
|
||||
-f Dockerfile-ui \
|
||||
--label timelimit-server-ui.sha=${{ steps.sha.outputs.sha }} \
|
||||
-t gitea.furb.it/${{ vars.FRONTEND_IMAGE }}:${{ steps.sha.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 }}:${{ steps.sha.outputs.sha }}
|
||||
docker push gitea.furb.it/${{ vars.FRONTEND_IMAGE }}:latest
|
||||
@@ -0,0 +1,12 @@
|
||||
FROM nginx:alpine
|
||||
LABEL maintainer="Kenneth van Ewijk (kennyboy55)"
|
||||
LABEL timelimit-server-ui.sha="unknown"
|
||||
|
||||
RUN rm -rf /usr/share/nginx/html/*
|
||||
|
||||
WORKDIR /usr/share/nginx/html/
|
||||
|
||||
COPY dist/* ./
|
||||
|
||||
EXPOSE 80
|
||||
CMD ["nginx", "-g", "daemon off;"]
|
||||
Reference in New Issue
Block a user