Skip to content

Commit f21bd53

Browse files
author
Toni Moreno Gimenez
committed
added CI to create distribution packages and docker images
1 parent 69056a9 commit f21bd53

3 files changed

Lines changed: 141 additions & 0 deletions

File tree

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: Release Docker Image CI
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*"
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Branch name
13+
id: branch_name
14+
run: |
15+
echo ::set-output name=SOURCE_NAME::${GITHUB_REF#refs/*/}
16+
echo ::set-output name=SOURCE_BRANCH::${GITHUB_REF#refs/heads/}
17+
echo ::set-output name=SOURCE_TAG::${GITHUB_REF#refs/tags/}
18+
- name: Version
19+
id: version
20+
run: |
21+
VERSION=`echo ${{ steps.branch_name.outputs.SOURCE_TAG }}| sed 's/v//g'`
22+
echo "version=$VERSION" >> $GITHUB_ENV
23+
-
24+
name: Set up Docker Buildx
25+
id: buildx
26+
uses: docker/setup-buildx-action@master
27+
-
28+
name: Cache Docker layers
29+
uses: actions/cache@v2
30+
with:
31+
path: /tmp/.buildx-cache
32+
key: ${{ runner.os }}-buildx-${{ github.sha }}
33+
restore-keys: |
34+
${{ runner.os }}-buildx-${{ github.sha }}
35+
-
36+
name: Login to Docker Hub
37+
uses: docker/login-action@v1
38+
with:
39+
username: ${{ secrets.DOCKER_HUB_USERNAME }}
40+
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
41+
42+
- name: Checkout
43+
uses: actions/checkout@v2
44+
with:
45+
fetch-depth: 0
46+
-
47+
name: Build and push Latest
48+
id: docker_build_latest
49+
uses: docker/build-push-action@v2
50+
with:
51+
context: ./
52+
file: ./Dockerfile
53+
builder: ${{ steps.buildx.outputs.name }}
54+
push: true
55+
tags: tonimoreno/snmpcollector:${{env.version}}
56+
cache-from: type=local,src=/tmp/.buildx-cache
57+
cache-to: type=local,dest=/tmp/.buildx-cache
58+
-
59+
name: Build and push Version
60+
id: docker_build_version
61+
uses: docker/build-push-action@v2
62+
with:
63+
context: ./
64+
file: ./Dockerfile
65+
builder: ${{ steps.buildx.outputs.name }}
66+
push: true
67+
tags: tonimoreno/snmpcollector:latest
68+
cache-from: type=local,src=/tmp/.buildx-cache
69+
cache-to: type=local,dest=/tmp/.buildx-cache
70+
71+
-
72+
name: Image digest
73+
run: echo ${{ steps.docker_build_version.outputs.digest }}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
on:
2+
push:
3+
# Sequence of patterns matched against refs/tags
4+
tags:
5+
- "v*" # Push events to matching v*, i.e. v1.0, v20.15.10
6+
7+
name: Create Release Packages
8+
9+
jobs:
10+
build:
11+
name: Create Release
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Branch name
15+
id: branch_name
16+
run: |
17+
echo ::set-output name=SOURCE_NAME::${GITHUB_REF#refs/*/}
18+
echo ::set-output name=SOURCE_BRANCH::${GITHUB_REF#refs/heads/}
19+
echo ::set-output name=SOURCE_TAG::${GITHUB_REF#refs/tags/}
20+
- name: Install Go
21+
uses: actions/setup-go@v2
22+
- name: Checkout code
23+
uses: actions/checkout@v2
24+
- name: Build Go Binary
25+
run: |
26+
go run build.go build
27+
- name: Install Node/NPM
28+
uses: actions/setup-node@v2
29+
with:
30+
node-version: '14.15.1'
31+
- name: Build Frontend
32+
run: |
33+
npm install
34+
PATH=$(npm bin):$PATH
35+
ng build --prod
36+
- name: Install FPM
37+
run: |
38+
sudo apt-get install ruby ruby-dev rubygems build-essential
39+
sudo gem install --no-document fpm
40+
- name: Build Packages
41+
run: |
42+
go run build.go pkg-all
43+
packaging/get-changelog.sh ${{ steps.branch_name.outputs.SOURCE_TAG }} > ${{ github.workspace }}-CHANGELOG.txt
44+
cat ${{ github.workspace }}-CHANGELOG.txt
45+
VERSION=`echo ${{ steps.branch_name.outputs.SOURCE_TAG }}| sed 's/v//g'`
46+
echo "version=$VERSION" >> $GITHUB_ENV
47+
48+
- name: Upload Releases Asset (RPM/DEB)
49+
id: upload-release-asset
50+
uses: softprops/action-gh-release@v1
51+
env:
52+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
53+
with:
54+
tag_name: ${{ github.ref }}
55+
name: Release ${{ steps.branch_name.outputs.SOURCE_TAG }}
56+
body_path: ${{ github.workspace }}-CHANGELOG.txt
57+
draft: false
58+
prerelease: false
59+
files: |
60+
LICENSE
61+
dist/snmpcollector-${{ env.version }}-1.x86_64.rpm
62+
dist/snmpcollector-${{ env.version }}-1.x86_64.rpm.sha1
63+
dist/snmpcollector_${{ env.version }}_amd64.deb
64+
dist/snmpcollector_${{ env.version }}_amd64.deb.sha1
65+

packaging/get-changelog.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
set -vx
3+
awk "/^# $1/{flag=1; next } /^# v/{flag=0} flag" CHANGELOG.md

0 commit comments

Comments
 (0)