running buildah github action to build the container below
FROM docker.io/library/dart:stable AS build
COPY . /app
WORKDIR /app
RUN dart compile exe ./bin/server.dart -o ./server
FROM scratch
COPY --from=build /runtime/ /
COPY --from=build /app/ /bin
EXPOSE 8080
CMD ["server"]
I get this error
[1/2] STEP 1/5: FROM docker.io/library/dart:stable AS build
Trying to pull docker.io/library/dart:stable...
Getting image source signatures
[...]
Writing manifest to image destination
Storing signatures
[1/2] STEP 2/5: COPY . /app
[1/2] STEP 3/5: WORKDIR /app
[1/2] STEP 4/5: RUN mkdir build
[1/2] STEP 5/5: RUN dart compile exe ./bin/server.dart -o ./server
"./bin/server.dart" file not found.
error building at STEP "RUN dart compile exe ./bin/server.dart -o ./server": error while running runtime: exit status 255
[2/2] STEP 1/5: FROM scratch
time="2022-12-02T09:04:48Z" level=error msg="exit status 255"
Error: Error: buildah exited with code 255
Trying to pull docker.io/library/dart:stable...
Getting image source signatures
[...]
Writing manifest to image destination
Storing signatures
error building at STEP "RUN dart compile exe ./bin/server.dart -o ./...
but running it locally with podman I have no issues
here is my github workflow
name: 'publish containers'
on:
push:
branches:
- master
# https://github.com/redhat-actions/push-to-registry/blob/main/.github/workflows/ghcr-push.yaml
env:
REGISTRY_USER: ${{ github.actor }}
REGISTRY_PASSWORD: ${{ github.token }}
IMAGE_REGISTRY: ghcr.io/${{ github.repository_owner }}
IMAGE_TAGS: v1 ${{ github.sha }}
jobs:
push-ghcr:
name: build and push image
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v3
# https://github.com/redhat-actions/podman-login
# https://github.com/redhat-actions/buildah-build#using-private-images
- name: login to ghcr
uses: redhat-actions/podman-login#v1
with:
username: ${{ env.REGISTRY_USER }}
password: ${{ env.REGISTRY_PASSWORD }}
registry: ${{ env.IMAGE_REGISTRY }}
- name: build image
id: build_image
uses: redhat-actions/buildah-build#v2
with:
image: server
tags: latest ${{ env.IMAGE_TAGS }}
containerfiles: |
server/Containerfile
- name: push to ghcr
uses: redhat-actions/push-to-registry#v2
id: push
with:
image: ${{ steps.build_image.outputs.image }}
tags: ${{ steps.build_image.outputs.tags }}
registry: ${{ env.IMAGE_REGISTRY }}
username: ${{ env.REGISTRY_USER }}
password: ${{ env.REGISTRY_PASSWORD }}
it seems to me that fails to pull the image from docker, but again it pulls ur locally
any idea what did I do wrong?
Related
I have a GitHub Action that needs to publish a Dockerfile to a specific organization.
The action looks like this:
name: Docker dataeng_github_metrics
# Run workflow on tags starting with v (eg. v2, v1.2.0)
on:
push:
branches: [ "master" ]
paths:
- ./data_pipelines/dataeng_github_metrics/*
pull_request:
branches: [ "master" ]
jobs:
Deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout#v1
- name: Login to GitHub Container Registry
uses: docker/login-action#v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GHCR_REGISTRY_TOKEN }}
- name: Build and Push Docker Image
uses: docker/build-push-action#v2
with:
file: ./data_pipelines/dataeng_github_metrics/Dockerfile
push: true # Will only build if this is not here
tags: |
ghcr.io/mirantis/dataeng_github_metrics:latest
The problem is that when I run the Dockerfile locally it works, but on this specific action workflow, it does not work. Instead, I get the following:
ERROR: failed to solve: failed to compute cache key: "/go.sum" not found: not found
Error: buildx failed with: ERROR: failed to solve: failed to compute cache key: "/go.sum" not found: not found
And upon inspecting the Dockerfile:
###############
# CACHE IMAGE #
###############
ARG GO_IMAGE=golang:1.17.3-alpine3.14
ARG BASE_IMAGE=alpine:3.14.2
FROM ${GO_IMAGE} AS cache
# Add the keys
ARG GITHUB_ID
ENV GITHUB_ID=$GITHUB_ID
ARG GITHUB_TOKEN
ENV GITHUB_TOKEN=$GITHUB_TOKEN
# Install Git
RUN apk add git
# TODO: ENCRYPT THE GITHUB_ID AND GITHUB_TOKEN
# Make Git Configuration
RUN git config \
--global \
url."https://${GITHUB_ID}:${GITHUB_TOKEN}#github.com/".insteadOf \
"https://github.com/"
WORKDIR /bin
COPY go.mod go.sum /bin/
RUN go mod download
##############
# BASE IMAGE #
##############
FROM cache AS dataeng_github_metrics
COPY . /bin
WORKDIR /bin
# Setup Git Terminal Prompt & Go Build
RUN go build .
###############
# FINAL IMAGE #
###############
FROM ${BASE_IMAGE}
COPY --from=dataeng_github_metrics /bin/dataeng_github_metrics bin/
ENTRYPOINT [ "bin/dataeng_github_metrics" ]
It fails at the following:
COPY go.mod go.sum /bin/
This builds locally so I don't understand what the issue is.
So to get past it, I had to add the full path to my context for the GitHub Action, I have another issue, but it's currently unrelated to the path context and not being able to find the files:
By adding in the following line, I was able to fix it by specifying the context path:
context: ./data_pipelines/dataeng_github_metrics/
name: Docker dataeng_github_metrics
# Run workflow on tags starting with v (eg. v2, v1.2.0)
on:
push:
branches: [ "master" ]
paths:
- ./data_pipelines/dataeng_github_metrics/*
pull_request:
branches: [ "master" ]
jobs:
Deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout#v1
- name: Login to GitHub Container Registry
uses: docker/login-action#v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GHCR_REGISTRY_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action#v2
- name: Build and Push Docker Image
uses: docker/build-push-action#v3
with:
context: ./data_pipelines/dataeng_github_metrics/
file: ./data_pipelines/dataeng_github_metrics/Dockerfile
push: true # Will only build if this is not here
tags: |
ghcr.io/mirantis/dataeng_github_metrics:latest
So I'm having an issue with my docker build action with github actions and I definitely feel like the issue is obvious but I am failing to get it.
So here is my Github Action
name: Build / Publish
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
build-and-push-docker-image:
name: Build Pinsel Docker image and push to repos
runs-on: ubuntu-latest
steps:
-
name: Checkout codebase
uses: actions/checkout#v2
-
name: Docker meta
id: meta
uses: docker/metadata-action#v3
with:
images: name/app
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
# Setup docker build
-
name: Set up Docker buildx
id: buildx
uses: docker/setup-buildx-action#v1
-
name: Login to Docker Hub
uses: docker/login-action#v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
-
name: Login into Github Packages
uses: docker/login-action#v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GHCR_PAT }}
-
name: Build image and push it to both registries
uses: docker/build-push-action#v2
with:
context: ../../
file: ./Dockerfile.prod
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
And here is my Dockerfile located in main directory
FROM node:16.4.2-alpine as build
RUN npm install -g pnpm#next-7
WORKDIR /app
ENV PATH /app/node_modules/.bin:$PATH
COPY /pnpm-lock.yaml ./
RUN pnpm fetch --prod
ADD . ./
RUN pnpm install -r --offline --prod
FROM nginx:1.21-alpine
COPY ./nginx/default.conf /etc/nginx/conf.d/default.conf
COPY --from=build /app/build /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
and lastly the error
#11 [build 5/8] COPY /package.json ./
#11 ERROR: failed to calculate checksum of ref ypf6stpm3t9h2xl6ezvwo7876::kvjk90tcw8wfykmdkvu1uvzgs: "/package.json": not found
#12 [stage-1 2/3] COPY ./nginx/default.conf /etc/nginx/conf.d/default.conf
#12 CANCELED
Dockerfile.prod:13
--------------------
11 |
12 | FROM nginx:1.21-alpine
13 | >>> COPY ./nginx/default.conf /etc/nginx/conf.d/default.conf
14 | COPY --from=build /app/build /usr/share/nginx/html
15 | EXPOSE 80
--------------------
error: failed to solve: failed to compute cache key: failed to calculate checksum of ref ypf6stpm3t9h2xl6ezvwo7876::kvjk90tcw8wfykmdkvu1uvzgs: "/nginx/default.conf": not found
Error: buildx failed with: error: failed to solve: failed to compute cache key: failed to calculate checksum of ref ypf6stpm3t9h2xl6ezvwo7876::kvjk90tcw8wfykmdkvu1uvzgs: "/nginx/default.conf": not found
Everything goes well on github actions until it needs to copy files. It says it can't find pnpm-lock.yaml, nor can it find ./nginx both of which are there.
I feel like the answer is super simple and I am just mentally fried and it's not standing out. If I can get a nudge in the right direction, it'd be appreciated!
I have realized that github/checkout puts you at the root directory of the github project, meaning I didn't need to add ../../ for context, I made the mistake of thinking I was navigating from the github action workflow directory.
So for anyone else who ends up this issue: actions/checkout will put you in the root directory of the repo, so you only need to use navigate via context if your dockerfiles are somewhere other than the root folder (like in their own docker folder)
We have a java application which uses maven, docker and Github actions.
The below snippet is from our Dockerfile.
FROM maven:3.6.3-jdk-8-openj9 AS builder
RUN mkdir /app
WORKDIR /app
ADD . .
RUN mvn clean install
And then we have a deploy.yml for GitHub actions. The issue is that on GitHub actions, maven always downloads the dependencies and then creates a jar and finally a docker image is created.
Using below tutorial, I have tried to implement caching in GitHub actions.
https://evilmartians.com/chronicles/build-images-on-github-actions-with-docker-layer-caching
The key for the cache in my case is calculated as below:
key: ${{ runner.os }}-buildx-${{ hashFiles('pom.xml') }}
Also made the following changes in the Dockerfile.
FROM maven:3.6.3-jdk-8-openj9 AS builder
RUN mkdir /app
WORKDIR /app
ADD . .
RUN mvn clean dependency:copy-dependencies
ADD . .
RUN mvn install
Still I do not see any significant changes in the reduction in build time.
What I am trying to do is that I want the maven dependencies download as a separate layer in docker image, and caching this docker layer which can be later re-used in the final docker image build.
If anyone can shade a light on this issue.
Use Buildkit(buildkit),now it is already part of every Docker Engine(19 and latest versions for sure).
Very nice Medium post
Introducing buildkit
This is nice example which you can use
docker cache ci
although with Python.
Reagarding the CI environment,Github Actions has fantastic build-push-action
Example
name: ci
on:
push:
branches:
- "master"
jobs:
docker:
runs-on: ubuntu-20.04
steps:
# Check out code
- name: Checkout
uses: actions/checkout#v2
# This is the a separate action that sets up buildx runner
- name: Set up Docker Buildx
uses: docker/setup-buildx-action#v1
# So now you can use Actions' own caching!
- name: Cache Docker layers
uses: actions/cache#v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Login to DockerHub
uses: docker/login-action#v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
# And make it available for the builds
- name: Build and push
uses: docker/build-push-action#v2
with:
context: .
push: false
tags: user/app:latest
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new
- name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
I'm having issues with my Github action where I'm trying to build my Docker image after building my jar and it throws this error:
Step 8/9 : COPY /home/runner/work/js-sites-client-api/js-sites-client-api/build/libs/client-portal-api.jar app.jar
COPY failed: file not found in build context or excluded by .dockerignore: stat home/runner/work/js-sites-client-api/js-sites-client-api/build/libs/client-portal-api.jar: file does not exist
Which doesn't make sense to me because I ran LS/PWD and I can see that the file IS there:
ls build/libs
cd build/libs
pwd
cd ../../
docker build . --file Dockerfile --tag ***/js-client-api:latest
shell: /usr/bin/bash -e {0}
env:
JAVA_HOME: /opt/hostedtoolcache/Java_Temurin-Hotspot_jdk/11.0.14-1/x64
GRADLE_BUILD_ACTION_CACHE_RESTORED: true
-------------OUTPUT of ls/pwd------------
client-portal-api.jar
/home/runner/work/js-sites-client-api/js-sites-client-api/build/libs
Below is my github action:
...
jobs:
build:
...
steps:
- uses: actions/checkout#v2
- name: Set up JDK 11
uses: actions/setup-java#v2
with:
java-version: '11'
distribution: 'temurin'
server-id: github # Value of the distributionManagement/repository/id field of the pom.xml
settings-path: ${{ github.workspace }} # location for the settings.xml file
- name: Change wrapper permissions
run: chmod +x ./gradlew
- name: Build with Gradle
uses: gradle/gradle-build-action#937999e9cc2425eddc7fd62d1053baf041147db7
with:
arguments: build
- name: Log in to Docker Hub
uses: docker/login-action#f054a8b539a109f9f41c372932f1ae047eff08c9
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build the Docker image
run: |
ls build/libs
cd build/libs
pwd
cd ../../
docker build . --file Dockerfile --tag ${{ secrets.DOCKER_USERNAME }}/js-client-api:latest --build-arg WORKDIR=${{ github.workspace }}
- name: Push the Docker image
run: docker push ${{ secrets.DOCKER_USERNAME }}/js-client-api:latest
Any help would be much appreciated!
This line in your Dockerfile is the issue:
COPY /home/runner/work/js-sites-client-api/js-sites-client-api/build/libs/client-portal-api.jar app.jar. In a Dockerfile COPY, the first argument is the location of the file(s) on the machine, which has to be a relative path, not an absolute one. Read more here
Multiple resources may be specified but the paths of files and directories will be interpreted as relative to the source of the context of the build.
Dockerfile :
FROM openjdk:11-jdk-slim
ARG JAR_FILE=target/*.jar
COPY ${JAR_FILE} backend.jar
ENTRYPOINT ["java","-jar","/backend.jar"]
deploy.yml:
jobs:
push_to_registry:
name: Push Docker image to Docker Hub
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout#v2
- name: Push to Docker Hub
uses: docker/build-push-action#v1
with:
path: backend
dockerfile: backend/Dockerfile
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
repository: myname/myrepo
tag_with_ref: true
Github actions result:
Status: Downloaded newer image for openjdk:11-jdk-slim
---> b4517d9514cb
Step 2/4 : ARG JAR_FILE=target/*.jar
---> Running in 640e9a32e282
Removing intermediate container 640e9a32e282
---> e9414330bf73
Step 3/4 : COPY ${JAR_FILE} backend.jar
COPY failed: no source files were specified
exit status 1
Error: exit status 1
I don't know why it says that source files were not specified, I have a other workflow, where I do exactly the same, but without build-push-action module, and it works fine.
Forgot to put a compile step before build:
- name: Maven Package
run: mvn -B clean compile package -DskipTests