-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
34 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
- name: Checkout Code | ||
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: Set up Docker Buildx | ||
id: buildx | ||
uses: docker/setup-buildx-action@v3 | ||
|
||
- name: Login to Dockerhub | ||
# if: github.event_name != 'pull_request' | ||
- name: Login to Docker Hub | ||
uses: docker/login-action@v3 | ||
with: | ||
username: ${{ secrets.FERN_DOCKER_USER }} | ||
password: ${{ secrets.FERN_DOCKER_PASSWORD }} | ||
|
||
- name: Docker meta | ||
id: meta_fern_reporter | ||
uses: docker/metadata-action@v5 | ||
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 | ||
- 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: anoop2811/fern-reporter:latest | ||
platforms: linux/amd64,linux/arm64,linux/arm/v7 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,39 @@ | ||
# Build stage | ||
FROM --platform=${BUILDPLATFORM:-linux/amd64} golang:1.21 as builder | ||
FROM --platform=${BUILDPLATFORM} golang:1.21-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 go mod and sum files | ||
COPY go.mod go.sum ./ | ||
RUN go mod tidy && go mod download | ||
|
||
# Copy the source from the current directory to the Working Directory inside the container | ||
COPY . . | ||
RUN go mod download | ||
COPY config/config.yaml ./ | ||
RUN mkdir ./migrations | ||
COPY pkg/db/migrations ./migrations/ | ||
|
||
# Build the Go app | ||
# RUN go mod tidy && go build -o fern . | ||
|
||
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/ | ||
COPY --from=build-env /app/config.yaml /app/ | ||
RUN mkdir /app/migrations | ||
COPY --from=build-env /app/migrations/* /app/migrations/ | ||
|
||
# Command to run | ||
ENTRYPOINT ["/app/fern"] |