+
Skip to content

Migrated to Github Actions and added Docker image definition #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/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
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
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载