-
Notifications
You must be signed in to change notification settings - Fork 1
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
61 additions
and
53 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,60 +1,43 @@ | ||
name: Create and publish a Docker image | ||
|
||
name: Main Branch CI | ||
|
||
# For all pushes to the main branch run the tests and push the image to the | ||
# GitHub registry under an edge tag so we can use it for the nightly | ||
# integration tests | ||
on: | ||
push: | ||
branches: [master] | ||
|
||
env: | ||
REGISTRY: ghcr.io | ||
IMAGE_NAME: ${{ github.repository }} | ||
|
||
jobs: | ||
docker: | ||
build-and-push-image: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
packages: write | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
- name: Prepare | ||
id: prep | ||
run: | | ||
DOCKER_IMAGE=ghcr.io/metcalfc/docker-action-examples | ||
VERSION=edge | ||
if [[ $GITHUB_REF == refs/tags/* ]]; then | ||
VERSION=${GITHUB_REF#refs/tags/v} | ||
fi | ||
if [ "${{ github.event_name }}" = "schedule" ]; then | ||
VERSION=nightly | ||
fi | ||
TAGS="${DOCKER_IMAGE}:${VERSION}" | ||
if [[ $VERSION =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then | ||
TAGS="$TAGS,${DOCKER_IMAGE}:latest" | ||
fi | ||
echo ::set-output name=tags::${TAGS} | ||
- name: Set up Docker Buildx | ||
id: buildx | ||
uses: docker/setup-buildx-action@v1 | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Cache Docker layers | ||
uses: actions/cache@v2 | ||
- name: Log in to the Container registry | ||
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 | ||
with: | ||
path: /tmp/.buildx-cache | ||
key: ${{ runner.os }}-buildx-${{ github.sha }} | ||
restore-keys: | | ||
${{ runner.os }}-buildx- | ||
- name: Login to ghcr | ||
if: github.event_name != 'pull_request' | ||
uses: docker/login-action@v1 | ||
registry: ${{ env.REGISTRY }} | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
- name: Extract metadata (tags, labels) for Docker | ||
id: meta | ||
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.repository_owner }} | ||
password: ${{ secrets.PAT_TOKEN }} | ||
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | ||
- name: Set up Docker Buildx | ||
id: buildx | ||
uses: docker/setup-buildx-action@v2 | ||
|
||
- name: Build and push | ||
id: docker_build | ||
uses: docker/build-push-action@v2 | ||
- name: Build and push Docker image | ||
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc | ||
with: | ||
builder: ${{ steps.buildx.outputs.name }} | ||
context: ./ | ||
file: ./Dockerfile | ||
push: ${{ github.event_name != 'pull_request' }} | ||
tags: ${{ steps.prep.outputs.tags }} | ||
context: . | ||
push: true | ||
platforms: linux/amd64,linux/arm64 | ||
tags: ${{ steps.meta.outputs.tags }} | ||
labels: ${{ steps.meta.outputs.labels }} |
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,8 +1,33 @@ | ||
FROM archlinux:base-devel | ||
RUN pacman -Sy --noconfirm && pacman -S --noconfirm binwalk file go perl-image-exiftool | ||
WORKDIR /go/src/app | ||
FROM --platform=$BUILDPLATFORM golang:alpine AS builder | ||
ARG TARGETPLATFORM | ||
ARG BUILDPLATFORM | ||
|
||
# Git is required for fetching the dependencies. | ||
RUN apk update && apk add --no-cache git bash libmagic libmagic-static gcc alpine-sdk file-dev && mkdir -p /build/biedatransfer | ||
|
||
WORKDIR /build/biedatransfer | ||
|
||
COPY go.mod go.mod | ||
COPY go.sum go.sum | ||
|
||
RUN go mod download -json | ||
|
||
COPY . . | ||
|
||
RUN go build . | ||
RUN mkdir -p /app && GOOS=${TARGETPLATFORM%%/*} GOARCH=${TARGETPLATFORM##*/} \ | ||
go build -ldflags='-s -w' -o /app/biedatransfer . | ||
|
||
# RUN echo "Running on architecture: $(uname -m), BUILDPLATFORM=$BUILDPLATFORM, TARGETPLATFORM=$TARGETPLATFORM" && exit 1 | ||
|
||
FROM alpine:edge | ||
|
||
# add testing repository | ||
RUN echo "http://dl-cdn.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories | ||
|
||
RUN apk update && apk add --no-cache libmagic exiftool binwalk ca-certificates | ||
|
||
COPY --from=builder /app/biedatransfer /app/biedatransfer | ||
|
||
LABEL org.opencontainers.image.description A docker image for the biedatransfer telegram bot. | ||
|
||
CMD ["/go/src/app/biedatransfer"] | ||
ENTRYPOINT ["/app/biedatransfer"] |