Skip to content

Production Container Image Builds and Brief Tests #106

Production Container Image Builds and Brief Tests

Production Container Image Builds and Brief Tests #106

# @license AGPL-3.0-or-later
#
# Copyright(C) 2025 Hong Xu <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
name: Production Container Image Builds and Brief Tests
on:
push:
branches: ["master"]
pull_request:
branches: ["master"]
schedule:
- cron: "0 3 * * *"
env:
IMAGE_NAME: delpa-redirection-server
DOCKER_CMD: docker
jobs:
build:
name: Production Container Image
runs-on: ubuntu-24.04
permissions:
packages: write
contents: read
steps:
- uses: actions/[email protected]
- name: Use Node.js
uses: actions/[email protected]
with:
node-version: 22
cache: "npm"
- name: Build
run: npm run build_prod
- name: Start the container
run: $DOCKER_CMD run --detach -p 3000:80 -p 3001:443 $IMAGE_NAME
- name: Install npm dependencies
run: npm ci
- name: Run test
run: npm run test_prod
# Push Only run below on master
- name: Log in to registry
if: github.ref == 'refs/heads/master'
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
- name: Push image
if: github.ref == 'refs/heads/master'
run: |
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME
# This changes all uppercase characters to lowercase.
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
VERSION=latest
echo IMAGE_ID=$IMAGE_ID
echo VERSION=$VERSION
$DOCKER_CMD tag $IMAGE_NAME $IMAGE_ID:$VERSION
$DOCKER_CMD push $IMAGE_ID:$VERSION
trigger-redeploy:
name: Trigger Redeploy
if: github.ref == 'refs/heads/master'
runs-on: ubuntu-24.04
needs: [build]
steps:
- name: Install jq
run: sudo apt-get install jq
- name: Trigger
run: |
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${{ secrets.DIGITALOCEAN_TOKEN }}" \
"https://api.digitalocean.com/v2/apps/${{ secrets.DIGITALOCEAN_APP_ID }}/deployments" \
| jq '.deployment.id' | grep -v null > /dev/null