mirror of
https://gitlab.archlinux.org/archlinux/archlinux-docker.git
synced 2025-08-06 14:17:18 +02:00
Get rid of Python deploy script
This commit is contained in:
parent
e791991ce6
commit
ef0c0eae64
@ -6,6 +6,7 @@ stages:
|
||||
- rootfs
|
||||
- image
|
||||
- test
|
||||
- upload
|
||||
- release
|
||||
- publish
|
||||
|
||||
@ -27,6 +28,7 @@ get_version:
|
||||
echo "BUILD_VERSION=$(date +%Y%m%d).$CI_JOB_ID" > build.env
|
||||
fi
|
||||
- export $(< build.env)
|
||||
- echo "PACKAGE_REGISTRY_URL=${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/rootfs/${BUILD_VERSION}" >> build.env
|
||||
artifacts:
|
||||
reports:
|
||||
dotenv: build.env
|
||||
@ -159,8 +161,9 @@ test:base-devel:
|
||||
- g++ -v
|
||||
- make -v
|
||||
|
||||
release:
|
||||
stage: release
|
||||
upload_and_commit_rootfs:
|
||||
stage: upload
|
||||
image: curlimages/curl:latest
|
||||
tags:
|
||||
- secure
|
||||
only:
|
||||
@ -168,10 +171,41 @@ release:
|
||||
- schedules
|
||||
variables:
|
||||
- $SCHEDULED_PUBLISH == "TRUE"
|
||||
before_script:
|
||||
- pacman -Syu --noconfirm python-gitlab
|
||||
script:
|
||||
- python ci/release.py
|
||||
- for group in base base-devel; do
|
||||
curl --header "JOB-TOKEN: ${CI_JOB_TOKEN}" --upload-file output/${group}.tar.xz ${PACKAGE_REGISTRY_URL}/${group}-${BUILD_VERSION}.tar.xz
|
||||
sed "/TEMPLATE_ROOTFS_FILE/d" Dockerfile.template > ci/${group}/Dockerfile
|
||||
sed -i "s|TEMPLATE_ROOTFS_URL|${PACKAGE_REGISTRY_URL}/${group}-${BUILD_VERSION}.tar.xz|" ci/${group}/Dockerfile
|
||||
sed -i "s|${group}.tar.xz|${group}-${BUILD_VERSION}.tar.xz|" output/${group}.tar.xz.SHA256
|
||||
sed -i "s|TEMPLATE_ROOTFS_HASH|$(cat output/${group}.tar.xz.SHA256)|" ci/${group}/Dockerfile
|
||||
done
|
||||
curl --request POST
|
||||
--header "PRIVATE-TOKEN: ${GITLAB_PROJECT_TOKEN}"
|
||||
--form "branch-add-base-devel-tags"
|
||||
--form "commit_message=Release ${BUILD_VERSION}"
|
||||
--form "actions[][action]=update"
|
||||
--form "actions[][file_path]=ci/base/Dockerfile"
|
||||
--form "actions[][content]=<ci/base/Dockerfile"
|
||||
--form "actions[][action]=update"
|
||||
--form "actions[][file_path]=ci/base-devel/Dockerfile"
|
||||
--form "actions[][content]=<ci/base-devel/Dockerfile"
|
||||
"${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/repository/commits"
|
||||
|
||||
release:
|
||||
stage: release
|
||||
image: registry.gitlab.com/gitlab-org/release-cli:latest
|
||||
tags:
|
||||
- secure
|
||||
only:
|
||||
refs:
|
||||
- schedules
|
||||
variables:
|
||||
- $SCHEDULED_PUBLISH == "TRUE"
|
||||
script:
|
||||
- release-cli create --name "Release ${BUILD_VERSION}" --description "Release ${BUILD_VERSION}"
|
||||
--tag-name v${BUILD_VERSION} --ref "add-base-devel-tags"
|
||||
--assets-link '{"name":"base-${BUILD_VERSION}.tar.xz","url":"${PACKAGE_REGISTRY_URL}/base-${BUILD_VERSION}.tar.xz"}'
|
||||
--assets-link '{"name":"base-devel-${BUILD_VERSION}.tar.xz","url":"${PACKAGE_REGISTRY_URL}/base-devel-${BUILD_VERSION}.tar.xz"}'
|
||||
|
||||
# Publish base to the Arch Linux group namespace: https://hub.docker.com/r/archlinux/archlinux
|
||||
publish:
|
||||
|
@ -1,92 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
"""
|
||||
Should only be called from GitLab CI!
|
||||
|
||||
Required env vars:
|
||||
- GITLAB_PROJECT_TOKEN
|
||||
- BUILD_VERSION
|
||||
- CI_PROJECT_ID
|
||||
- CI_PROJECT_URL
|
||||
"""
|
||||
|
||||
import os
|
||||
import re
|
||||
from pathlib import Path
|
||||
import gitlab
|
||||
|
||||
token = os.environ['GITLAB_PROJECT_TOKEN']
|
||||
build_version = os.environ['BUILD_VERSION']
|
||||
project_id = os.environ['CI_PROJECT_ID']
|
||||
project_url = os.environ['CI_PROJECT_URL']
|
||||
|
||||
|
||||
def upload(name):
|
||||
print(f"Uploading {name}.tar.xz")
|
||||
filename = f"{name}-{build_version}.tar.xz"
|
||||
uploaded_url = project.upload(
|
||||
filename, filepath=f"output/{name}.tar.xz"
|
||||
)["url"]
|
||||
template = Path("Dockerfile.template").read_text()
|
||||
full_url = f"{project_url}{uploaded_url}"
|
||||
replaced = template.replace("TEMPLATE_ROOTFS_URL", full_url)
|
||||
rootfs_sha256 = Path(f"output/{name}.tar.xz.SHA256").read_text()[0:64]
|
||||
hash_string = f"{rootfs_sha256} {filename}"
|
||||
replaced = replaced.replace(
|
||||
"TEMPLATE_ROOTFS_HASH", hash_string
|
||||
)
|
||||
# Remove the line containing TEMPLATE_ROOTFS_FILE
|
||||
replaced = re.sub(".*TEMPLATE_ROOTFS_FILE.*\n", "", replaced)
|
||||
return replaced, full_url
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
gl = gitlab.Gitlab("https://gitlab.archlinux.org", token)
|
||||
project = gl.projects.get(project_id)
|
||||
|
||||
base_replaced, base_full_url = upload("base")
|
||||
base_devel_replaced, base_devel_full_url = upload("base-devel")
|
||||
|
||||
print("Templating Dockerfiles")
|
||||
data = {
|
||||
"branch": "add-base-devel-tags",
|
||||
"commit_message": f"Release {build_version}",
|
||||
"actions": [
|
||||
{
|
||||
"action": "update",
|
||||
"file_path": "ci/base/Dockerfile",
|
||||
"content": base_replaced,
|
||||
},
|
||||
{
|
||||
"action": "update",
|
||||
"file_path": "ci/base-devel/Dockerfile",
|
||||
"content": base_devel_replaced,
|
||||
},
|
||||
],
|
||||
}
|
||||
project.commits.create(data)
|
||||
|
||||
print("Creating release")
|
||||
release = project.releases.create(
|
||||
{
|
||||
"name": f"Release {build_version}",
|
||||
"tag_name": f"v{build_version}",
|
||||
"description": f"Release {build_version}",
|
||||
"ref": "add-base-devel-tags",
|
||||
"assets": {
|
||||
"links": [
|
||||
{
|
||||
"name": "base.tar.xz",
|
||||
"url": base_full_url,
|
||||
"link_type": "package",
|
||||
},
|
||||
{
|
||||
"name": "base-devel.tar.xz",
|
||||
"url": base_devel_full_url,
|
||||
"link_type": "package",
|
||||
}
|
||||
]
|
||||
},
|
||||
}
|
||||
)
|
||||
print("Created release", release.get_id())
|
Loading…
Reference in New Issue
Block a user