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

ci: Move docker build to GitLab CI. Add scheduled job for Docker container...

ci: Move docker build to GitLab CI. Add scheduled job for Docker container package updates. Add RenovateBot config.
parent 0a0fa4cd
No related branches found
No related tags found
No related merge requests found
......@@ -115,37 +115,37 @@ jobs:
branch: gh-pages
folder: dist/spa
# DOCKER RELATED
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to DockerHub
uses: docker/login-action@v2
with:
username: griefed
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v3
with:
context: .
build-args: |
BRANCH_OR_TAG=${{ github.ref_name }}
HOSTER=github.com
file: ./Dockerfile
platforms: linux/amd64,linux/arm/v7,linux/arm64
push: true
tags: |
ghcr.io/griefed/ltt-mapmaker:latest
ghcr.io/griefed/ltt-mapmaker:${{ steps.tag.outputs.tag }}
griefed/ltt-mapmaker:latest
griefed/ltt-mapmaker:${{ steps.tag.outputs.tag }}
# # DOCKER RELATED
# - name: Set up QEMU
# uses: docker/setup-qemu-action@v2
# - name: Set up Docker Buildx
# uses: docker/setup-buildx-action@v2
# - name: Login to DockerHub
# uses: docker/login-action@v2
# with:
# username: griefed
# password: ${{ secrets.DOCKERHUB_TOKEN }}
# - name: Login to GitHub Container Registry
# uses: docker/login-action@v2
# with:
# registry: ghcr.io
# username: ${{ github.actor }}
# password: ${{ secrets.GITHUB_TOKEN }}
# - name: Build and push
# uses: docker/build-push-action@v3
# with:
# context: .
# build-args: |
# BRANCH_OR_TAG=${{ github.ref_name }}
# HOSTER=github.com
# file: ./Dockerfile
# platforms: linux/amd64,linux/arm/v7,linux/arm64
# push: true
# tags: |
# ghcr.io/griefed/ltt-mapmaker:latest
# ghcr.io/griefed/ltt-mapmaker:${{ steps.tag.outputs.tag }}
# griefed/ltt-mapmaker:latest
# griefed/ltt-mapmaker:${{ steps.tag.outputs.tag }}
electron:
needs: release
......
stages:
- test
- release
- build
services:
- name: ghcr.io/griefed/gitlab-ci-cd:2.0.8
alias: docker
workflow:
rules:
- if: '$CI_MERGE_REQUEST_EVENT_TYPE == "detached"'
when: never
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
when: never
- when: always
test quasar:
image: ghcr.io/griefed/gitlab-ci-cd:2.0.8
stage: test
cache:
paths:
- node_modules/
before_script:
- npm install
- rm -Rf dist
script:
- 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"'
pages:
image: ghcr.io/griefed/gitlab-ci-cd:2.0.8
stage: build
cache:
paths:
- node_modules/
before_script:
- npm install
- rm -Rf dist
script:
- quasar build
- cp -Rf dist/spa/* public/
artifacts:
paths:
- public
expire_in: 1 week
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"'
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."
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": [
"config:base"
],
"packageRules": [
{
"extends": "config:base",
"matchPaths": ["package.json"]
}
],
"labels": ["dependencies"],
"assignees": ["Griefed"]
}
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