Skip to content

Commit

Permalink
refactor: Trying new approach
Browse files Browse the repository at this point in the history
  • Loading branch information
anoop2811 committed Jan 7, 2024
1 parent 67e485c commit 4b40cf2
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 103 deletions.
101 changes: 18 additions & 83 deletions .github/workflows/build-server.yml
Original file line number Diff line number Diff line change
@@ -1,100 +1,35 @@
# This is a basic workflow to help you get started with Actions
name: Build and Push Docker Image

name: build

# Controls when the workflow will run
on:
workflow_dispatch:
push:
branches:
- 'main'
- 'dev'
- 'v*.*.*'
- 'wip-github-actions'
- main
- wip-github-actions
tags:
- 'v*.*.*'
pull_request:
branches:
- 'main'
- 'dev'
- 'v*.*.*'
- 'wip-github-actions'

permissions:
contents: read
packages: write

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
build-fern-reporter:
build-and-push:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
platform:
- linux/amd64
- linux/arm/v6
- linux/arm/v7
- linux/arm64
- linux/arm64/v8

steps:
- name: Prepare
run: |
platform=${{ matrix.platform }}
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
- name: Checkout
uses: actions/checkout@v4

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: 1.21

- name: Tests
run: |
go mod tidy
# go test -v ./...
- name: Checkout Code
uses: actions/checkout@v2

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

- name: Login to Dockerhub
# if: github.event_name != 'pull_request'
uses: docker/login-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.FERN_DOCKER_USER }}
password: ${{ secrets.FERN_DOCKER_PASSWORD }}
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Docker meta
id: meta_fern_reporter
uses: docker/metadata-action@v5
- name: Build and Push
uses: docker/build-push-action@v2
with:
images: |
anoop2811/fern-reporter
tags: |
type=schedule
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha
- name: Build and push
uses: docker/build-push-action@v5
with:
# outputs: "type=registry,push=true"
# push: ${{ github.event_name != 'pull_request' }}
context: .
file: ./Dockerfile
push: true
# context: .
platforms: ${{ matrix.platform }}
# platforms: linux/amd64,linux/arm/v7,linux/arm64/v8
tags: ${{ steps.meta_fern_reporter.outputs.tags }}
# tags: anoop2811/fern-reporter:latest
# labels: ${{ steps.meta_fern_reporter.outputs.labels }}
tags: yourusername/fern:latest
platforms: linux/amd64,linux/arm64,linux/arm/v7

36 changes: 16 additions & 20 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,37 +1,33 @@
# Build stage
FROM --platform=${BUILDPLATFORM:-linux/amd64} golang:1.21 as builder
FROM --platform=${BUILDPLATFORM} golang:1.16-alpine AS build-env

ARG TARGETPLATFORM
ARG BUILDPLATFORM
# Set up arguments for multi-architecture support
ARG TARGETOS
ARG TARGETARCH

ENV GO111MODULE=on
# Set up the environment
ENV GO111MODULE=on \
CGO_ENABLED=0

# Set the working directory inside the container
WORKDIR /app

# Copy the source from the current directory to the working Directory inside the container
COPY . .
# Copy go mod and sum files
COPY go.mod go.sum ./
RUN go mod download

# Build the Go app
# RUN go mod tidy && go build -o fern .
# Copy the source from the current directory to the Working Directory inside the container
COPY . .

# Build the Go app
RUN GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -o fern .

# Final stage: Run stage
FROM --platform=${BUILDPLATFORM:-linux/amd64} gcr.io/distroless/static:nonroot


# Set the working directory in the container
# Final stage
FROM --platform=${TARGETPLATFORM} alpine
WORKDIR /app

# Copy the pre-built binary file from the previous stage
COPY --from=builder /app/fern /app/fern

USER nonroot:nonroot

# Command to run the binary
CMD ["/app/fern"]
# Copy the binary from the build-env
COPY --from=build-env /app/fern /app/

# Command to run
ENTRYPOINT ["/app/fern"]

0 comments on commit 4b40cf2

Please sign in to comment.