Skip to content

Commit

Permalink
feat: add action to build image on tag
Browse files Browse the repository at this point in the history
  • Loading branch information
peterxcli committed Feb 2, 2024
1 parent 25bce03 commit 90104e9
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 0 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/build-backend-image.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Build and Push Docker Image on Tag

on:
push:
tags:
- '*'

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}-backend

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Log into the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata for the Docker image
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Build and push the Docker image
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile_Backend
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
39 changes: 39 additions & 0 deletions .github/workflows/build-notifier-image.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Build and Push Docker Image on Tag

on:
push:
tags:
- '*'

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}-notifier

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Log into the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata for the Docker image
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Build and push the Docker image
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile_Notifier
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
File renamed without changes.
26 changes: 26 additions & 0 deletions Dockerfile_Notifier
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Build Stage
FROM golang:1.21 AS build

# Set the working directory
WORKDIR /app

# Copy all files to the working directory
COPY . .

# Download all dependencies
RUN go mod download

# Set CGO_ENABLED to 1
# ENV CGO_ENABLED=1

# Build the Go application
RUN CGO_ENABLED=1 GOOS=linux go build -o /app/main ./cmd/notification.go

# Runtime Stage
FROM busybox AS runtime

# Copy the binary from the build stage to the runtime stage
COPY --from=build /app/main /app

# Set the entry point to execute the binary directly
ENTRYPOINT ["/app"]

0 comments on commit 90104e9

Please sign in to comment.