Skip to content
Snippets Groups Projects
Verified Commit e070c056 authored by Griefed's avatar Griefed :joystick:
Browse files

ci: Add docker build and jobs

parent a264e4c5
No related branches found
No related tags found
No related merge requests found
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
assignees:
- "Griefed"
labels:
- "dependencies"
- "github-actions"
target-branch: "dependabot"
pull-request-branch-name:
separator: "-"
- package-ecosystem: "npm"
directory: "/"
schedule:
interval: "weekly"
assignees:
- "Griefed"
labels:
- "dependencies"
- "npm"
target-branch: "dependabot"
pull-request-branch-name:
separator: "-"
- package-ecosystem: "docker"
directory: "/"
schedule:
interval: "weekly"
assignees:
- "Griefed"
labels:
- "dependencies"
- "docker"
target-branch: "dependabot"
pull-request-branch-name:
separator: "-"
name: Create GitHub Release after GitLab tag mirror
on:
push:
tags:
- '[0-9]+.[0-9]+.[0-9]+'
jobs:
release:
runs-on: ubuntu-latest
steps:
# GET LATEST CODE
- name: Checkout latest code
uses: actions/checkout@v3
with:
fetch-depth: 0
# EXTRACT TAG FROM PUSH
- name: Get tag
id: tag
uses: dawidd6/action-get-tag@v1
- name: Use tag
run: echo ${{steps.tag.outputs.tag}}
# GENERATE CHANGELOG, RELEASE
- id: conventional_changelog
uses: ardalanamini/auto-changelog@master
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Create Release
id: create_release
uses: actions/create-release@latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{steps.tag.outputs.tag}}
body: |
Automatic release of version: **${{steps.tag.outputs.tag}}**
**Changes in this release:**
${{ steps.conventional_changelog.outputs.changelog }}
draft: false
prerelease: false
- name: Setup Node.js environment
uses: actions/setup-node@v3.4.0
with:
# Version Spec of the version to use. Examples: 12.x, 10.15.1, >=10.15.0
node-version: '>= 16.9.1'
# Set this option if you want the action to check for the latest available version that satisfies the version spec
check-latest: false
- name: Install Quasar
run: npm install -g @quasar/cli
- name: Install packages
run: npm install
- name: Build project for NGINX release package
run: quasar build
- name: List files
run: pwd && ls -al *
- uses: actions/upload-artifact@v3
with:
name: build-artifacts-quasar
path: dist/spa/
if-no-files-found: warn # 'warn' or 'ignore' are also available, defaults to `warn`
# NGINX Archives
- name: Create NGINX Archive tar.gz
run: |
echo "**** Creating archive of quasar build ****"
tar -cvzf spcao-NGINX-${{ steps.tag.outputs.tag }}.tar.gz dist/spa
- name: Create NGINX Archive zip
uses: papeloto/action-zip@v1
with:
files: dist/spa
recursive: true
dest: spcao-NGINX-${{ steps.tag.outputs.tag }}.zip
stages: stages:
- test - test
- docs - docs
- release
- build
services:
- name: ghcr.io/griefed/gitlab-ci-cd:2.0.8
alias: docker
workflow: workflow:
rules: rules:
...@@ -11,7 +17,7 @@ workflow: ...@@ -11,7 +17,7 @@ workflow:
- when: always - when: always
test quasar: test quasar:
image: griefed/gitlab-ci-cd:2.0.8 image: ghcr.io/griefed/gitlab-ci-cd:2.0.8
stage: test stage: test
cache: cache:
paths: paths:
...@@ -22,8 +28,68 @@ test quasar: ...@@ -22,8 +28,68 @@ test quasar:
script: script:
- quasar build - quasar build
test docker:
stage: test
image: ghcr.io/griefed/gitlab-ci-cd:2.0.8
variables:
project_name: $CI_PROJECT_NAME
SEMANTIC_RELEASE_PACKAGE: $CI_PROJECT_NAME
before_script:
- docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
- docker buildx create --use --name grfdbuilder
script:
- docker buildx build --no-cache --platform linux/amd64,linux/arm/v7,linux/arm64
--build-arg BRANCH_OR_TAG=$CI_COMMIT_REF_NAME
--build-arg HOSTER=$CI_SERVER_HOST
--file Dockerfile .
rules:
- if: '$CI_SERVER_HOST == "git.griefed.de"'
release:
needs: ['test docker','test quasar']
stage: release
image: ghcr.io/griefed/gitlab-ci-cd:2.0.8
variables:
project_name: $CI_PROJECT_NAME
SEMANTIC_RELEASE_PACKAGE: $CI_PROJECT_NAME
script:
- npx semantic-release
only:
- master
except:
refs:
- tags
variables:
- $CI_COMMIT_TITLE =~ /^RELEASE:.+$/
build:
stage: build
image: ghcr.io/griefed/gitlab-ci-cd:2.0.8
variables:
project_name: $CI_PROJECT_NAME
SEMANTIC_RELEASE_PACKAGE: $CI_PROJECT_NAME
before_script:
- docker login -u "$DOCKERHUB_USER" -p "$DOCKERHUB_TOKEN" docker.io
- docker login -u "$DOCKERHUB_USER" -p "$GITHUB_TOKEN" ghcr.io
- docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
- docker buildx create --use --name grfdbuilder
script:
- docker buildx build
--push
--no-cache
--platform linux/amd64,linux/arm/v7,linux/arm64
--build-arg BRANCH_OR_TAG=$CI_COMMIT_REF_NAME
--build-arg HOSTER=$CI_SERVER_HOST
--tag "ghcr.io/$DOCKERHUB_USER/$DOCKERHUB_REPO:$CI_COMMIT_TAG"
--tag "ghcr.io/$DOCKERHUB_USER/$DOCKERHUB_REPO:latest"
--tag "index.docker.io/$DOCKERHUB_USER/$DOCKERHUB_REPO:$CI_COMMIT_TAG"
--tag "index.docker.io/$DOCKERHUB_USER/$DOCKERHUB_REPO:latest"
--file Dockerfile .
rules:
- if: '$CI_COMMIT_TAG =~ /^\d+\.\d+\.\d+$/ && $CI_SERVER_HOST == "git.griefed.de"'
pages: pages:
image: griefed/gitlab-ci-cd:2.0.8 image: ghcr.io/griefed/gitlab-ci-cd:2.0.8
stage: docs stage: docs
cache: cache:
paths: paths:
...@@ -39,4 +105,111 @@ pages: ...@@ -39,4 +105,111 @@ pages:
artifacts: artifacts:
paths: paths:
- public - public
expire_in: 1 week expire_in: 1 week
\ No newline at end of file
Check Packages:on-schedule:
only:
- schedules
before_script:
- |-
echo "Preparing package versions comparison."
# Check and, if necessary, update git user and mail
if [[ "$(git config --list | grep user.name)" != "user.name=$GIT_USER" ]];then
git config --global user.name $GIT_USER
fi
if [[ "$(git config --list | grep user.email)" != "user.email=$GIT_MAIL" ]];then
git config --global user.email $GIT_MAIL
fi
# Clean system of potentially interrupting images
docker image rm -f $DOCKERHUB_USER/$DOCKERHUB_REPO:latest
docker image rm -f $DOCKERHUB_REPO
rm -rf /tmp/$CI_PROJECT_PATH
mkdir -p /tmp/$CI_PROJECT_PATH
echo "Preparations complete."
script:
- |-
echo "Comparing package versions." && \
# Clone the repository
git clone $CI_PROJECT_URL.git /tmp/$CI_PROJECT_PATH && \
cd /tmp/$CI_PROJECT_PATH && \
if [ ! -s "package_versions.txt" ];then
echo "No package_versions.txt available..." && \
# Gather package information from latest build
docker run --rm --entrypoint /bin/sh -v /tmp/$CI_PROJECT_PATH:/tmp $DOCKERHUB_USER/$DOCKERHUB_REPO:latest -c '\
apk info -v > /tmp/package_versions.txt && \
sort -o /tmp/package_versions.txt /tmp/package_versions.txt && \
chmod 777 /tmp/package_versions.txt' && \
# Checkout our branch
git checkout -f $CI_DEFAULT_BRANCH && \
wait && \
# Add and commit new file to repository
git add package_versions.txt && \
git commit -m 'chore: Add list of package versions.' && \
# Push the changes to the remote
git push "https://$GIT_USER:$GITLAB_TOKEN@$CI_SERVER_HOST/$CI_PROJECT_PATH.git" --all && \
# Nice
echo "package_versions.txt added."
elif [ -s "package_versions.txt" ];then
echo "Local package_versions.txt available..." && \
# Build local image for new package versions list
docker build --no-cache --tag $DOCKERHUB_REPO . && \
# Get packages from newly build local image
docker run --rm --entrypoint /bin/sh -v /tmp/$CI_PROJECT_PATH:/tmp $DOCKERHUB_REPO -c '\
apk info -v > /tmp/package_versions_new.txt && \
sort -o /tmp/package_versions_new.txt /tmp/package_versions_new.txt && \
chmod 777 /tmp/package_versions_new.txt' && \
# Get checksum of old packages
OLD_CHECKSUM=$(md5sum package_versions.txt | cut -f1 -d" ") && \
# Get checksum of new packages
NEW_CHECKSUM=$(md5sum package_versions_new.txt | cut -f1 -d" ")
# If new checksum is not the same as old checksum, we have new versions
if [ "${OLD_CHECKSUM}" != "${NEW_CHECKSUM}" ]; then
echo "Checksums differ. Updating..." && \
# Checkout our branch
git checkout -f $CI_DEFAULT_BRANCH && \
# Copy the new package versions list to repository
mv -f package_versions_new.txt package_versions.txt && \
wait && \
# Add and commit new file to repository
git add package_versions.txt && \
git commit -m 'build: Update installed packages in Docker container.' && \
# Push the changes to the remote
git push "https://$GIT_USER:$GITLAB_TOKEN@$CI_SERVER_HOST/$CI_PROJECT_PATH.git" --all && \
# Nice
echo "Packages updated."
else
echo "No package updates available."
fi
fi
echo "Comparison complete."
after_script:
- |-
echo "Cleaning up."
docker image rm -f $DOCKERHUB_USER/$DOCKERHUB_REPO:latest
docker image rm -f $DOCKERHUB_REPO
rm -rf /tmp/$CI_PROJECT_PATH
echo "Done."
FROM griefed/gitlab-ci-cd:2.0.8 AS builder
ARG BRANCH_OR_TAG=main
ARG HOSTER=git.griefed.de
RUN \
git clone \
-b $BRANCH_OR_TAG \
https://$HOSTER/Griefed/ServerPackCreator-Addons-Overview.git \
/tmp/ServerPackCreator-Addons-Overview && \
cd /tmp/ServerPackCreator-Addons-Overview && \
npm install && \
quasar build
FROM ghcr.io/linuxserver/nginx:1.20.2
LABEL maintainer="Griefed <griefed@griefed.de>"
RUN \
rm -rf \
/config/www && \
echo "**** Cleanup ****" && \
rm -rf \
/root/.cache \
/tmp/*
COPY --from=builder /tmp/ServerPackCreator-Addons-Overview/dist/spa/ /config/www
EXPOSE 80 443
server {
listen 80 default_server;
listen 443 ssl;
root /app/ServerPackCreator-Addons-Overview;
index index.php index.html index.htm;
server_name _;
ssl_certificate /config/keys/cert.crt;
ssl_certificate_key /config/keys/cert.key;
client_max_body_size 0;
location / {
root /app/ServerPackCreator-Addons-Overview;
index index.html index.htm;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment