deemix-docker/.gitlab-ci.yml
2022-03-12 08:08:28 +00:00

113 lines
5.5 KiB
YAML

variables:
DOCKER_CLI_EXPERIMENTAL: enabled
PLATFORMS: "linux/amd64,linux/arm64,linux/arm/v7"
PACKAGE_REGISTRY_URL: "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/${CI_COMMIT_SHORT_SHA}/${CI_COMMIT_SHORT_SHA}"
# Docker build will download via this url
PACKAGE_REGISTRY_URL_STATIC: "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/static/static"
npm_config_cache: "$CI_PROJECT_DIR/.npm"
PKG_CACHE_PATH: "$CI_PROJECT_DIR/.nodejs-bin"
YARN_CACHE_FOLDER: "$CI_PROJECT_DIR/.yarn-cache"
stages:
- build-deemix
- build-docker-image
- create-release
build-deemix:
image: node:16
stage: build-deemix
cache:
key: "$CI_COMMIT_REF_SLUG"
paths:
- .npm
- .nodejs-bin
- .yarn-cache
policy: pull-push
before_script:
- apt update && apt install -y --no-install-recommends zip git curl jq
# Dropping static first package first
- echo get package ID of static
- export STATIC_ID=$(curl "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages" | jq '.[] | select(.name == "static") | .id')
- echo $STATIC_ID
- |
curl --request DELETE --header "PRIVATE-TOKEN: ${PAT_TOKEN}" "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/${STATIC_ID}"
script:
- git clone --depth=1 https://gitlab.com/RemixDev/deemix-gui.git --recursive src
# Patching pkg.targets to our need
- jq '.pkg.targets = ["node16-linuxstatic-x64","node16-linuxstatic-arm64","node16-linuxstatic-armv7"]' src/server/package.json > tmp.$$.json && mv tmp.$$.json src/server/package.json
- cd src
- ls -alh
- yarn config set network-timeout 1000000 -g
- yarn add pkg@latest
- yarn install-all
- yarn dist-server
- ls -al dist/
# Upload static files (overwritten) per build
- |
curl --header "JOB-TOKEN: ${CI_JOB_TOKEN}" --upload-file dist/deemix-server-x64 ${PACKAGE_REGISTRY_URL_STATIC}/deemix-server-linux-amd64
- |
curl --header "JOB-TOKEN: ${CI_JOB_TOKEN}" --upload-file dist/deemix-server-arm64 ${PACKAGE_REGISTRY_URL_STATIC}/deemix-server-linux-arm64
- |
curl --header "JOB-TOKEN: ${CI_JOB_TOKEN}" --upload-file dist/deemix-server-armv7 ${PACKAGE_REGISTRY_URL_STATIC}/deemix-server-linux-arm
# Upload per CI_COMMIT_SHORT_SHA
- |
curl --header "JOB-TOKEN: ${CI_JOB_TOKEN}" --upload-file dist/deemix-server-x64 ${PACKAGE_REGISTRY_URL}/deemix-server-linux-amd64
- |
curl --header "JOB-TOKEN: ${CI_JOB_TOKEN}" --upload-file dist/deemix-server-arm64 ${PACKAGE_REGISTRY_URL}/deemix-server-linux-arm64
- |
curl --header "JOB-TOKEN: ${CI_JOB_TOKEN}" --upload-file dist/deemix-server-armv7 ${PACKAGE_REGISTRY_URL}/deemix-server-linux-arm
only:
refs:
- master
create-release:
stage: create-release
image: registry.gitlab.com/gitlab-org/release-cli:latest
#rules:
# - if: $CI_COMMIT_TAG
script:
- export DATE=$(date +%Y%m%d) # Cant tag same twice use $CI_COMMIT_SHA for a while
- |
release-cli create --name "Release $CI_COMMIT_SHORT_SHA" --tag-name $CI_COMMIT_SHORT_SHA --description "rollback to this version by changing the TAG release code above, registry.gitlab.com/bockiii/deemix-docker:TAG" \
--assets-link "{\"name\":\"deemix-server-linux-amd64\",\"url\":\"${PACKAGE_REGISTRY_URL}/deemix-server-linux-amd64\"}" \
--assets-link "{\"name\":\"deemix-server-linux-arm64\",\"url\":\"${PACKAGE_REGISTRY_URL}/deemix-server-linux-arm64\"}" \
--assets-link "{\"name\":\"deemix-server-linux-armv7\",\"url\":\"${PACKAGE_REGISTRY_URL}/deemix-server-linux-arm\"}" \
--assets-link "{\"name\":\"deemix-server-linux-static-amd64\",\"url\":\"${PACKAGE_REGISTRY_URL_STATIC}/deemix-server-linux-amd64\"}" \
--assets-link "{\"name\":\"deemix-server-linux-static-arm64\",\"url\":\"${PACKAGE_REGISTRY_URL_STATIC}/deemix-server-linux-arm64\"}" \
--assets-link "{\"name\":\"deemix-server-linux-static-armv7\",\"url\":\"${PACKAGE_REGISTRY_URL_STATIC}/deemix-server-linux-arm\"}" \
--assets-link "{\"name\":\"deemix-server-docker-pull\",\"url\":\"https://registry.gitlab.com/bockiii/deemix-docker:${CI_COMMIT_SHORT_SHA}\"}"
only:
refs:
- master
build-docker-image:
image: docker:20
stage: build-docker-image
services:
- docker:dind
before_script:
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
- apk add --update curl jq && rm -rf /var/cache/apk/*
- export CI_JOB_TIMESTAMP=$(date --utc -Iseconds)
- export DATE=$(date +%Y%m%d)
script:
# Download latest buildx bin from github
- mkdir -p ~/.docker/cli-plugins/
- BUILDX_LATEST_BIN_URI=$(curl -s -L https://github.com/docker/buildx/releases/latest | grep 'linux-amd64' | grep 'href' | sed 's/.*href="/https:\/\/github.com/g; s/amd64".*/amd64/g')
- curl -s -L ${BUILDX_LATEST_BIN_URI} -o ~/.docker/cli-plugins/docker-buildx
- chmod a+x ~/.docker/cli-plugins/docker-buildx
# Get and run the latest docker/binfmt tag to use its qemu parts
- BINFMT_IMAGE_TAG=$(curl -s https://registry.hub.docker.com/v2/repositories/docker/binfmt/tags | jq '.results | sort_by(.last_updated)[-1].name' -r)
- docker run --rm --privileged docker/binfmt:${BINFMT_IMAGE_TAG}
# create the multibuilder
- docker buildx create --name multibuilder
- docker buildx use multibuilder
# build and push
- docker buildx build --platform "${PLATFORMS}" --build-arg BUILDDATE=$DATE --build-arg STATIC_URL=$PACKAGE_REGISTRY_URL_STATIC -t ${CI_REGISTRY_IMAGE}:${CI_COMMIT_SHORT_SHA} -t ${CI_REGISTRY_IMAGE} . --push
only:
refs:
- master