From 1144ed67d5111d6d1c147eb6703dd01451831962 Mon Sep 17 00:00:00 2001 From: Ivan Krutov Date: Tue, 1 Feb 2022 07:34:07 +0300 Subject: [PATCH] Migrated to Github Actions and added Docker image definition --- .github/workflows/build.yml | 37 ++++++++++++++++++++++++++ .github/workflows/release.yml | 50 +++++++++++++++++++++++++++++++++++ .travis.yml | 20 -------------- Dockerfile | 3 +++ ci/build.sh | 8 ++++++ ci/docker-push.sh | 9 +++++++ ci/test.sh | 4 +++ go.mod | 3 +++ 8 files changed, 114 insertions(+), 20 deletions(-) create mode 100644 .github/workflows/build.yml create mode 100644 .github/workflows/release.yml delete mode 100644 .travis.yml create mode 100644 Dockerfile create mode 100755 ci/build.sh create mode 100755 ci/docker-push.sh create mode 100755 ci/test.sh create mode 100644 go.mod diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..870705b --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,37 @@ +name: build + +on: + push: + branches: + - master + +jobs: + init: + runs-on: ubuntu-latest + if: github.repository == 'aerokube/init' + steps: + - uses: actions/checkout@v2 + + - name: Setup Golang + uses: actions/setup-go@v2 + with: + go-version: 1.17.x + + - uses: actions/cache@v1 + with: + path: ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + + - name: Test + run: ci/test.sh + + - name: Build + run: ci/build.sh + + - name: Latest image + env: + DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} + DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} + run: ci/docker-push.sh latest diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..834b4c8 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,50 @@ +name: release + +on: + release: + types: [published] + +jobs: + init: + runs-on: ubuntu-latest + if: github.repository == 'aerokube/init' + steps: + - uses: actions/checkout@v2 + + - name: Setup Golang + uses: actions/setup-go@v2 + with: + go-version: 1.17.x + + - uses: actions/cache@v1 + with: + path: ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + + - name: Test + run: ci/test.sh + + - name: Build + run: ci/build.sh + + - name: Prepare release version + run: echo "RELEASE_VERSION=${GITHUB_REF:10}" >> $GITHUB_ENV + + - uses: AButler/upload-release-assets@v2.0 + with: + files: 'dist/*' + repo-token: ${{ secrets.GITHUB_TOKEN }} + + - name: Release image + env: + DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} + DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} + run: ci/docker-push.sh $RELEASE_VERSION + + - name: Latest release image + env: + DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} + DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} + run: ci/docker-push.sh latest-release \ No newline at end of file diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 70dad95..0000000 --- a/.travis.yml +++ /dev/null @@ -1,20 +0,0 @@ -sudo: required -language: go - -go: - - 1.10.x - -script: - - gox -os "linux" -arch "386 amd64" -output "dist/{{.Dir}}_{{.OS}}_{{.Arch}}" -ldflags "-X main.buildStamp=`date -u '+%Y-%m-%d_%I:%M:%S%p'` -X main.gitRevision=`git describe --tags || git rev-parse HEAD` -s -w" - -install: - - go get -u github.com/mitchellh/gox - -deploy: - - provider: releases - api-key: $GITHUB_TOKEN - file_glob: true - file: dist/* - skip_cleanup: true - on: - tags: true diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..fa0255c --- /dev/null +++ b/Dockerfile @@ -0,0 +1,3 @@ +FROM scratch + +COPY init /sbin/init \ No newline at end of file diff --git a/ci/build.sh b/ci/build.sh new file mode 100755 index 0000000..1a7b69c --- /dev/null +++ b/ci/build.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +set -e + +export GO111MODULE="on" +go get -u github.com/mitchellh/gox # cross compile +GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -ldflags "-X main.buildStamp=`date -u '+%Y-%m-%d_%I:%M:%S%p'` -X main.gitRevision=`git describe --tags || echo rev:$(git rev-parse HEAD)` -s -w" +gox -os "linux" -arch "386 amd64" -output "dist/{{.Dir}}_{{.OS}}_{{.Arch}}" -ldflags "-X main.buildStamp=`date -u '+%Y-%m-%d_%I:%M:%S%p'` -X main.gitRevision=`git describe --tags || git rev-parse HEAD` -s -w" \ No newline at end of file diff --git a/ci/docker-push.sh b/ci/docker-push.sh new file mode 100755 index 0000000..daeaad4 --- /dev/null +++ b/ci/docker-push.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +set -e + +docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD" +docker build -t "$GITHUB_REPOSITORY" . +docker tag "$GITHUB_REPOSITORY" "$GITHUB_REPOSITORY:$1" +docker push "$GITHUB_REPOSITORY" +docker push "$GITHUB_REPOSITORY:$1" \ No newline at end of file diff --git a/ci/test.sh b/ci/test.sh new file mode 100755 index 0000000..44e8770 --- /dev/null +++ b/ci/test.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +export GO111MODULE="on" +go test -v -race ./... diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..fd490fa --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module github.com/aerokube/init + +go 1.17