Skip to content

Commit

Permalink
Improvements
Browse files Browse the repository at this point in the history
Signed-off-by: Mriyam Tamuli <mbtamuli@gmail.com>
  • Loading branch information
mbtamuli committed Jan 17, 2024
1 parent bffded0 commit e43f68c
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 0 deletions.
32 changes: 32 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Include any files or directories that you don't want to be copied to your
# container here (e.g., local build artifacts, temporary files, etc.).
#
# For more help, visit the .dockerignore file reference guide at
# https://docs.docker.com/go/build-context-dockerignore/

**/.DS_Store
**/.classpath
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/bin
**/charts
**/docker-compose*
**/compose*
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
LICENSE
README.md
52 changes: 52 additions & 0 deletions .github/workflows/05-image-build-push.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: 05-image-build-push

on: [push]

jobs:
go-binary:
runs-on: ubuntu-latest
steps:
-
name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}
-
name: Set up QEMU
uses: docker/setup-qemu-action@v3
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
-
name: Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
-
name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
-
name: Build and push
uses: docker/build-push-action@v5
with:
context: "{{defaultContext}}"
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max
- # Temp fix
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
21 changes: 21 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# syntax=docker/dockerfile:1

ARG GO_VERSION=1.21
FROM --platform=$BUILDPLATFORM golang:${GO_VERSION} AS build
WORKDIR /src

RUN --mount=type=cache,target=/go/pkg/mod/ \
--mount=type=bind,source=go.sum,target=go.sum \
--mount=type=bind,source=go.mod,target=go.mod \
go mod download -x

ARG TARGETARCH

RUN --mount=type=cache,target=/go/pkg/mod/ \
--mount=type=bind,target=. \
CGO_ENABLED=0 GOARCH=$TARGETARCH go build -o /go/bin/app ./go-program

FROM gcr.io/distroless/static-debian12:latest AS final

COPY --from=build /go/bin/app /
CMD ["/app"]
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ Various proofs of concept examples using Github Actions 🤖
| [![01-run-on-push](https://github.com/mbtamuli/github-actions-pocs/actions/workflows/01-run-on-push.yaml/badge.svg)](https://github.com/mbtamuli/github-actions-pocs/actions/workflows/01-run-on-push.yaml) | Runs on push event to any branch. |
| [![02-run-after-another](https://github.com/mbtamuli/github-actions-pocs/actions/workflows/02-run-after-another.yaml/badge.svg)](https://github.com/mbtamuli/github-actions-pocs/actions/workflows/02-run-after-another.yaml) | Run after another workflow, in this case after [01-run-on-push](https://github.com/mbtamuli/github-actions-pocs/actions/workflows/01-run-on-push.yaml) or [03-run-on-pull-request](https://github.com/mbtamuli/github-actions-pocs/actions/workflows/03-run-on-pr.yaml) |
| [![03-run-on-pull-request](https://github.com/mbtamuli/github-actions-pocs/actions/workflows/03-run-on-pr.yaml/badge.svg)](https://github.com/mbtamuli/github-actions-pocs/actions/workflows/03-run-on-pr.yaml) | Runs on pull request event for any branch. |
| [![04-go-binary](https://github.com/mbtamuli/github-actions-pocs/actions/workflows/04-go-binary.yaml/badge.svg)](https://github.com/mbtamuli/github-actions-pocs/actions/workflows/04-go-binary.yaml) | Build a go binary |
| [![05-docker-image-build-push](https://github.com/mbtamuli/github-actions-pocs/actions/workflows/05-docker-image-build-push.yaml/badge.svg)](https://github.com/mbtamuli/github-actions-pocs/actions/workflows/05-docker-image.yaml) | Build container image and push to GHCR |


## Reference
Expand Down

0 comments on commit e43f68c

Please sign in to comment.