-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add auto docker build using github actions
- Loading branch information
Showing
4 changed files
with
118 additions
and
7 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 |
---|---|---|
@@ -0,0 +1,74 @@ | ||
name: Docker Build | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
paths: | ||
- Dockerfile | ||
- .dockerignore | ||
- .github/workflows/docker-build.yml | ||
- "*.go" | ||
workflow_dispatch: | ||
|
||
jobs: | ||
build: | ||
name: Build Image | ||
runs-on: ubuntu-latest | ||
permissions: | ||
packages: write | ||
contents: read | ||
|
||
steps: | ||
- name: Checkout current repo | ||
uses: actions/checkout@v3 | ||
|
||
- name: Login to GitHub Container Registry | ||
uses: docker/login-action@v1 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Login to DockerHub | ||
uses: docker/login-action@v1 | ||
with: | ||
username: ${{ secrets.DOCKERHUB_USERNAME }} | ||
password: ${{ secrets.DOCKERHUB_TOKEN }} | ||
|
||
- name: Set ENV Variables | ||
run: | | ||
IMG="$(echo "${{ github.repository }}" | tr '[:upper:]' '[:lower:]')" | ||
echo "IMAGE=${IMG}" >> $GITHUB_ENV | ||
echo "GIT_SHA=$(echo ${{ github.sha }} | cut -c1-7)" >> $GITHUB_ENV | ||
echo "BUILD_DATE=$(date +'%Y-%m-%d %H:%M:%S')" >> $GITHUB_ENV | ||
echo "GIT_REF=$(git symbolic-ref -q --short HEAD || git describe --tags --exact-match)" >> $GITHUB_ENV | ||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@v1 | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v1 | ||
|
||
- name: Build and push | ||
id: docker_build | ||
uses: docker/build-push-action@v2 | ||
with: | ||
context: . | ||
platforms: linux/amd64,linux/arm64 | ||
push: true | ||
cache-from: type=gha | ||
cache-to: type=gha,mode=max | ||
tags: | | ||
ghcr.io/${{ env.IMAGE }}:latest | ||
ghcr.io/${{ env.IMAGE }}:${{ env.GIT_SHA }} | ||
${{ env.IMAGE }}:latest | ||
${{ env.IMAGE }}:${{ env.GIT_SHA }} | ||
labels: | | ||
org.opencontainers.image.authors=${{ github.repository_owner }} | ||
org.opencontainers.image.created=${{ env.BUILD_DATE }} | ||
org.opencontainers.image.description=Created from commit ${{ env.GIT_SHA }} and ref ${{ env.GIT_REF }} | ||
org.opencontainers.image.ref.name=${{ env.GIT_REF }} | ||
org.opencontainers.image.revision=${{ github.sha }} | ||
org.opencontainers.image.source=https://github.com/${{ github.repository }} | ||
org.opencontainers.image.version=${{ env.GIT_SHA }} |
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
name: Update Docker Hub Description | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
paths: | ||
- README.md | ||
- .github/workflows/update-docker-readme.yml | ||
|
||
jobs: | ||
build-image: | ||
name: Build | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Docker Hub Description | ||
uses: peter-evans/dockerhub-description@v3 | ||
with: | ||
username: ${{ secrets.DOCKERHUB_USERNAME }} | ||
password: ${{ secrets.DOCKERHUB_PASSWORD }} |
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,11 +1,11 @@ | ||
# Build Stage: Build bot using the alpine image, also install doppler in it | ||
FROM golang:1.18.0-alpine3.15 AS builder | ||
RUN apk add --update --no-cache git | ||
WORKDIR /app | ||
COPY . . | ||
RUN CGO_ENABLED=0 GOOS=`go env GOHOSTOS` GOARCH=`go env GOHOSTARCH` go build -o out/RestrictChannelRobot | ||
|
||
# Run Stage: Run bot using the bot and doppler binary copied from build stage | ||
FROM gcr.io/distroless/static | ||
COPY --from=builder /app/out/RestrictChannelRobot / | ||
|
||
CMD ["/RestrictChannelRobot"] |
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