Move to Forgejo CI
All checks were successful
CI Pipeline / build (push) Successful in 1m12s
CI Pipeline / build-and-push-docker (push) Successful in 36s
CI Pipeline / publish-executables (push) Successful in 8s

This commit is contained in:
MassiveBox 2024-04-18 12:14:36 +02:00
parent 519796d3d1
commit 924b96e0db
Signed by: massivebox
GPG key ID: 9B74D3A59181947D
3 changed files with 123 additions and 89 deletions

View file

@ -0,0 +1,123 @@
name: CI Pipeline
on:
push:
branches:
- master
tags:
- 'v*'
jobs:
build:
runs-on: ubuntu-22.04
steps:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: '1.22'
- name: Checkout code
uses: actions/checkout@v3
- name: Build
run: |
go mod tidy
echo Building for linux/amd64...
GOOS=linux GOARCH=amd64 go build -o ecodash_x86 src/main/main.go
echo Building for linux/arm...
GOOS=linux GOARCH=arm go build -o ecodash_arm src/main/main.go
- name: Stash artifacts
uses: actions/upload-artifact@v3
with:
path: |
ecodash_x86
ecodash_arm
build-and-push-docker:
runs-on: ubuntu-22.04
needs: build
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Docker meta
id: meta
uses: https://github.com/docker/metadata-action@v5
with:
images: git.massivebox.net/massivebox/ecodash
tags: |
type=ref,event=branch
type=semver,pattern={{version}}
type=semver,pattern=v{{major}}
type=semver,pattern={{major}}.{{minor}}
- name: Install QEMU
run: sudo apt-get update && sudo apt-get install -y qemu-user-static
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
registry: git.massivebox.net
username: ${{ github.actor }}
password: ${{ secrets.FORGE_TOKEN }}
- name: Download artifacts
uses: actions/download-artifact@v3
with:
name: artifact
- name: Move dockerfile
run: mv .forgejo/workflows/Dockerfile Dockerfile
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
publish-executables:
runs-on: ubuntu-22.04
needs: build
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Download artifacts
uses: actions/download-artifact@v3
with:
name: artifact
- name: Prepare build artifacts
run: |
mkdir release
mv ecodash_x86 ecodash
zip -r release/ecodash-x86.zip templates ecodash
mv ecodash_arm ecodash
zip -r release/ecodash-arm.zip templates ecodash
- name: Upload artifacts to CI
uses: actions/upload-artifact@v3
with:
path: |
ecodash_x86
ecodash_arm
templates
overwrite: true
- name: Create release
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
uses: actions/forgejo-release@v1
with:
direction: upload
url: https://git.massivebox.net
repo: massivebox/ecodash
release-dir: release
tag: ${{ github.ref_name }}
token: ${{ secrets.FORGE_TOKEN }}

89
jenkins/Jenkinsfile vendored
View file

@ -1,89 +0,0 @@
pipeline {
agent any
environment {
DOCKER_REGISTRY='git.massivebox.net'
BUILDER_NAME='mbuilder'
SERVICE='ecodash/ecodash'
}
stages {
stage('Run linter and build') {
agent { docker { image 'golang' } }
steps {
checkout scm
sh 'curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin'
sh 'go mod tidy'
sh 'golangci-lint run'
sh 'env GOOS=linux GOARCH=amd64 go build -o ecodash_x86 src/main/main.go'
stash includes: 'ecodash_x86', name: 'ecodash_x86'
sh 'env GOOS=linux GOARCH=arm go build -o ecodash_arm src/main/main.go'
stash includes: 'ecodash_arm', name: 'ecodash_arm'
stash includes: 'jenkins/Dockerfile', name: 'dockerfile'
stash includes: 'templates/**', name: 'templates'
}
}
stage('Prepare container build') {
steps {
sh """
docker buildx create --name $BUILDER_NAME
docker buildx use $BUILDER_NAME
docker buildx inspect --bootstrap
cp jenkins/Dockerfile ./Dockerfile
"""
withCredentials([usernamePassword(credentialsId: 'gitea-credentials', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {
sh 'docker login -u $USERNAME -p $PASSWORD $DOCKER_REGISTRY'
}
unstash 'dockerfile'
unstash 'ecodash_x86'
unstash 'ecodash_arm'
unstash 'templates'
}
}
stage('Build and push container on push to master') {
when {
anyOf {
branch 'master'
buildingTag()
}
}
steps {
sh 'docker buildx build --platform linux/amd64,linux/arm64 --push -t $DOCKER_REGISTRY/$SERVICE:latest .'
}
}
stage('Build and push container on tag') {
when { buildingTag() }
steps {
script {
def formattedTag = env.TAG_NAME.replaceFirst(/^v/, '')
sh 'docker buildx build --platform linux/amd64,linux/arm64 --push -t $DOCKER_REGISTRY/$SERVICE:$formattedTag .'
}
}
}
stage('Publish build artifacts on tag') {
when { buildingTag() }
steps {
sh 'mv ecodash_x86 ecodash; zip -r ecodash-x86.zip templates ecodash'
archiveArtifacts artifacts: "ecodash-x86.zip"
sh 'mv ecodash_arm ecodash; zip -r ecodash-arm.zip templates ecodash'
archiveArtifacts artifacts: "ecodash-arm.zip"
}
}
}
post {
always {
// cleanup
sh 'docker buildx rm $BUILDER_NAME'
}
}
}