Skip to content

Commit

Permalink
Build using github actions
Browse files Browse the repository at this point in the history
  • Loading branch information
tyhal committed Jun 28, 2021
1 parent 5e38cc2 commit 9c8cd0e
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 10 deletions.
84 changes: 84 additions & 0 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: Docker

on:
push:
# Publish `master` as Docker `latest` image.
branches:
- master

# Publish `v1.2.3` tags as releases.
tags:
- v*

# Run tests for any PRs.
pull_request:


jobs:

test:
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'

steps:
- uses: actions/checkout@v2

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1

- name: Crie
id: crie_build
uses: docker/build-push-action@v2
with:
file: ./Dockerfile
builder: ${{ steps.buildx.outputs.name }}
push: false
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache

push-dockerhub:
runs-on: ubuntu-latest
if: github.event_name == 'push'

permissions:
contents: read
packages: write

steps:
- uses: actions/checkout@v2

- name: set environ
run: |
# Strip git ref prefix from version
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
# Strip "v" prefix from tag name
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
# Use Docker `latest` tag convention
[ "$VERSION" == "master" ] && VERSION=latest
echo "VERSION=$VERSION" >> $GITHUB_ENV
- name: Login to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1

- name: Crie
id: crie_build
uses: docker/build-push-action@v2
with:
file: ./Dockerfile
builder: ${{ steps.buildx.outputs.name }}
push: true
tags: ${{ secrets.DOCKER_HUB_USERNAME }}/crie:${{ env.VERSION }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache

10 changes: 5 additions & 5 deletions .mergify.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
queue_rules:
- name: default
conditions:
- status-success=ci/dockercloud-stage
- status-success=Docker / test (pull_request)

pull_request_rules:
- name: automatic merge for Dependabot pull requests
conditions:
- base=master
- author~=^dependabot(|-preview)\[bot\]$
- status-success=ci/dockercloud-stage
- status-success=Docker / test (pull_request)
actions:
queue:
name: default
- name: automatic merge for Renovate pull requests
conditions:
- base=master
- author=renovate[bot]
- status-success=ci/dockercloud-stage
- status-success=Docker / test (pull_request)
actions:
queue:
name: default
Expand All @@ -26,15 +26,15 @@ pull_request_rules:
- title~=^\[Snyk\]
- head~=^snyk-fix
- check-success~=^security/snyk
- status-success=ci/dockercloud-stage
- status-success=Docker / test (pull_request)
actions:
queue:
name: default
- name: automatic merge for ImgBot pull requests
conditions:
- base=master
- author=imgbot[bot]
- status-success=ci/dockercloud-stage
- status-success=Docker / test (pull_request)
actions:
queue:
name: default
7 changes: 2 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@ FROM go_layer as crie_layer
COPY go.mod /crie/go.mod
COPY go.sum /crie/go.sum
WORKDIR /crie
# --mount=type=cache,target=/go/pkg/mod
RUN go mod download
RUN --mount=type=cache,target=/go/pkg/mod go mod download
COPY cmd /crie/cmd
COPY internal /crie/internal
COPY pkg /crie/pkg
# --mount=type=cache,target=/root/.cache/go-build
RUN go build ./cmd/crie
RUN --mount=type=cache,target=/root/.cache/go-build go build ./cmd/crie

FROM alpine:3.12.1 as clang_layer
RUN apk --no-cache add clang
Expand Down Expand Up @@ -62,7 +60,6 @@ RUN apk add --no-cache python3 py3-pip $BUILD_LIBS \
COPY --from=hadolint_layer /bin/hadolint /bin/hadolint

# [ Bash ]
COPY --from=shfmt_layer /go/bin/shfmt /bin/shfmt
COPY --from=hadolint_layer /bin/shellcheck /bin/shellcheck

# [ Golang ]
Expand Down

0 comments on commit 9c8cd0e

Please sign in to comment.