Skip to content

Commit

Permalink
Merge pull request #2 from vania-pooh/master
Browse files Browse the repository at this point in the history
Migrated to Github Actions and added Docker image definition
  • Loading branch information
vania-pooh authored Feb 1, 2022
2 parents 78f8e1c + 1144ed6 commit 08b4246
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 20 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -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
50 changes: 50 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
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
20 changes: 0 additions & 20 deletions .travis.yml

This file was deleted.

3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM scratch

COPY init /sbin/init
8 changes: 8 additions & 0 deletions ci/build.sh
Original file line number Diff line number Diff line change
@@ -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"
9 changes: 9 additions & 0 deletions ci/docker-push.sh
Original file line number Diff line number Diff line change
@@ -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"
4 changes: 4 additions & 0 deletions ci/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

export GO111MODULE="on"
go test -v -race ./...
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/aerokube/init

go 1.17

0 comments on commit 08b4246

Please sign in to comment.