chore(docker): optimize docker build workflow

This commit is contained in:
Orhun Parmaksız 2023-05-11 00:29:11 +03:00
parent ce51c184a5
commit dc499e402e
No known key found for this signature in database
GPG Key ID: F83424824B3E4B90
2 changed files with 22 additions and 11 deletions

View File

@ -15,14 +15,14 @@ on:
jobs:
docker:
name: Docker Build and Push
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Docker meta
id: meta
uses: docker/metadata-action@v3
uses: docker/metadata-action@v4
with:
images: |
orhunp/rustypaste
@ -35,12 +35,17 @@ jobs:
type=raw,value=latest
type=semver,pattern={{version}}
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
with:
platforms: arm64
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1
uses: docker/setup-buildx-action@v2
- name: Cache Docker layers
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
@ -49,14 +54,14 @@ jobs:
- name: Login to Docker Hub
if: github.event_name != 'pull_request'
uses: docker/login-action@v1
uses: docker/login-action@v2
with:
username: orhunp
password: ${{ secrets.DOCKER_TOKEN }}
- name: Login to GHCR
if: github.event_name != 'pull_request'
uses: docker/login-action@v1
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
@ -64,16 +69,24 @@ jobs:
- name: Build and push
id: docker_build
uses: docker/build-push-action@v2
uses: docker/build-push-action@v4
with:
context: ./
file: ./Dockerfile
platforms: linux/amd64,linux/arm64
builder: ${{ steps.buildx.outputs.name }}
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
sbom: true
provenance: true
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
- name: Scan the image
uses: anchore/sbom-action@v0
with:
image: ghcr.io/${{ github.repository_owner }}/rustypaste/rustypaste
- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}

View File

@ -14,9 +14,7 @@ RUN cp target/release/rustypaste build-out/
FROM scratch
WORKDIR /app
COPY --from=builder \
/app/build-out/rustypaste \
/app/config.toml ./
COPY --from=builder /app/build-out/rustypaste .
ENV SERVER__ADDRESS=0.0.0.0:8000
EXPOSE 8000
USER 1000:1000