-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added CI to create distribution packages and docker images
- Loading branch information
Toni Moreno Gimenez
committed
Feb 15, 2022
1 parent
69056a9
commit f21bd53
Showing
3 changed files
with
141 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
name: Release Docker Image CI | ||
|
||
on: | ||
push: | ||
tags: | ||
- "v*" | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Branch name | ||
id: branch_name | ||
run: | | ||
echo ::set-output name=SOURCE_NAME::${GITHUB_REF#refs/*/} | ||
echo ::set-output name=SOURCE_BRANCH::${GITHUB_REF#refs/heads/} | ||
echo ::set-output name=SOURCE_TAG::${GITHUB_REF#refs/tags/} | ||
- name: Version | ||
id: version | ||
run: | | ||
VERSION=`echo ${{ steps.branch_name.outputs.SOURCE_TAG }}| sed 's/v//g'` | ||
echo "version=$VERSION" >> $GITHUB_ENV | ||
- | ||
name: Set up Docker Buildx | ||
id: buildx | ||
uses: docker/setup-buildx-action@master | ||
- | ||
name: Cache Docker layers | ||
uses: actions/cache@v2 | ||
with: | ||
path: /tmp/.buildx-cache | ||
key: ${{ runner.os }}-buildx-${{ github.sha }} | ||
restore-keys: | | ||
${{ runner.os }}-buildx-${{ github.sha }} | ||
- | ||
name: Login to Docker Hub | ||
uses: docker/login-action@v1 | ||
with: | ||
username: ${{ secrets.DOCKER_HUB_USERNAME }} | ||
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} | ||
|
||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
with: | ||
fetch-depth: 0 | ||
- | ||
name: Build and push Latest | ||
id: docker_build_latest | ||
uses: docker/build-push-action@v2 | ||
with: | ||
context: ./ | ||
file: ./Dockerfile | ||
builder: ${{ steps.buildx.outputs.name }} | ||
push: true | ||
tags: tonimoreno/snmpcollector:${{env.version}} | ||
cache-from: type=local,src=/tmp/.buildx-cache | ||
cache-to: type=local,dest=/tmp/.buildx-cache | ||
- | ||
name: Build and push Version | ||
id: docker_build_version | ||
uses: docker/build-push-action@v2 | ||
with: | ||
context: ./ | ||
file: ./Dockerfile | ||
builder: ${{ steps.buildx.outputs.name }} | ||
push: true | ||
tags: tonimoreno/snmpcollector:latest | ||
cache-from: type=local,src=/tmp/.buildx-cache | ||
cache-to: type=local,dest=/tmp/.buildx-cache | ||
|
||
- | ||
name: Image digest | ||
run: echo ${{ steps.docker_build_version.outputs.digest }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
on: | ||
push: | ||
# Sequence of patterns matched against refs/tags | ||
tags: | ||
- "v*" # Push events to matching v*, i.e. v1.0, v20.15.10 | ||
|
||
name: Create Release Packages | ||
|
||
jobs: | ||
build: | ||
name: Create Release | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Branch name | ||
id: branch_name | ||
run: | | ||
echo ::set-output name=SOURCE_NAME::${GITHUB_REF#refs/*/} | ||
echo ::set-output name=SOURCE_BRANCH::${GITHUB_REF#refs/heads/} | ||
echo ::set-output name=SOURCE_TAG::${GITHUB_REF#refs/tags/} | ||
- name: Install Go | ||
uses: actions/setup-go@v2 | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
- name: Build Go Binary | ||
run: | | ||
go run build.go build | ||
- name: Install Node/NPM | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: '14.15.1' | ||
- name: Build Frontend | ||
run: | | ||
npm install | ||
PATH=$(npm bin):$PATH | ||
ng build --prod | ||
- name: Install FPM | ||
run: | | ||
sudo apt-get install ruby ruby-dev rubygems build-essential | ||
sudo gem install --no-document fpm | ||
- name: Build Packages | ||
run: | | ||
go run build.go pkg-all | ||
packaging/get-changelog.sh ${{ steps.branch_name.outputs.SOURCE_TAG }} > ${{ github.workspace }}-CHANGELOG.txt | ||
cat ${{ github.workspace }}-CHANGELOG.txt | ||
VERSION=`echo ${{ steps.branch_name.outputs.SOURCE_TAG }}| sed 's/v//g'` | ||
echo "version=$VERSION" >> $GITHUB_ENV | ||
- name: Upload Releases Asset (RPM/DEB) | ||
id: upload-release-asset | ||
uses: softprops/action-gh-release@v1 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
tag_name: ${{ github.ref }} | ||
name: Release ${{ steps.branch_name.outputs.SOURCE_TAG }} | ||
body_path: ${{ github.workspace }}-CHANGELOG.txt | ||
draft: false | ||
prerelease: false | ||
files: | | ||
LICENSE | ||
dist/snmpcollector-${{ env.version }}-1.x86_64.rpm | ||
dist/snmpcollector-${{ env.version }}-1.x86_64.rpm.sha1 | ||
dist/snmpcollector_${{ env.version }}_amd64.deb | ||
dist/snmpcollector_${{ env.version }}_amd64.deb.sha1 | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/bash | ||
set -vx | ||
awk "/^# $1/{flag=1; next } /^# v/{flag=0} flag" CHANGELOG.md |