From daa4d2cdfd2295c3c44d4f210169a9bbc53e6efb Mon Sep 17 00:00:00 2001 From: roy_fuel <96140895+rfuelsh@users.noreply.github.com> Date: Thu, 13 Jan 2022 13:47:27 -0500 Subject: [PATCH] Build and Push Fuel-Core Docker Image (#110) * Updating docker build&publish based on master only --- .github/workflows/ci.yml | 87 +++++++++++++++++++ deployment/Dockerfile | 5 +- .../docker-compose.yml => docker-compose.yml | 8 +- 3 files changed, 94 insertions(+), 6 deletions(-) rename deployment/docker-compose.yml => docker-compose.yml (52%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index de984d73d72..f32848e6d66 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,6 +11,7 @@ on: env: CARGO_TERM_COLOR: always RUSTFLAGS: -D warnings + REGISTRY: ghcr.io jobs: build: @@ -88,3 +89,89 @@ jobs: uses: katyo/publish-crates@v1 with: registry-token: ${{ secrets.CARGO_REGISTRY_TOKEN }} + + build-publish-master-image: + needs: build + if: github.ref == 'refs/heads/master' + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Docker meta + id: meta + uses: docker/metadata-action@v3 + with: + images: | + ghcr.io/fuellabs/fuel-core + tags: | + type=sha + type=ref,event=branch + type=ref,event=tag + flavor: | + latest=${{ github.ref == 'refs/heads/master' }} + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Log in to the ghcr.io registry + uses: docker/login-action@v1 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push the image to ghcr.io + uses: docker/build-push-action@v2 + with: + context: . + file: deployment/Dockerfile + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max + + build-publish-release-image: + # Build & Publish Docker Image Per Fuel-Core Release + needs: publish + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Docker meta + id: meta + uses: docker/metadata-action@v3 + with: + images: | + ghcr.io/fuellabs/fuel-core + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Log in to the ghcr.io registry + uses: docker/login-action@v1 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push the image to ghcr.io + uses: docker/build-push-action@v2 + with: + context: . + file: deployment/Dockerfile + push: true + tags: ${{ github.ref_name }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max diff --git a/deployment/Dockerfile b/deployment/Dockerfile index e394d0f9754..4d4c706287a 100644 --- a/deployment/Dockerfile +++ b/deployment/Dockerfile @@ -9,7 +9,6 @@ RUN apt-get update && \ clang \ libclang-dev \ libssl-dev \ - && mkdir -p ~/.ssh && ssh-keyscan github.com >> ~/.ssh/known_hosts \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* @@ -17,7 +16,7 @@ WORKDIR /build/ COPY . . -RUN --mount=type=ssh cargo build --release +RUN cargo build --release # Stage 2: Run FROM ubuntu:20.04 as run @@ -47,4 +46,4 @@ COPY --from=builder /build/target/release/fuel-core.d . # hadolint ignore=DL3025 CMD exec ./fuel-core --ip ${IP} --port ${PORT} --db-path ${DB_PATH} -EXPOSE ${PORT} \ No newline at end of file +EXPOSE ${PORT} diff --git a/deployment/docker-compose.yml b/docker-compose.yml similarity index 52% rename from deployment/docker-compose.yml rename to docker-compose.yml index d13a90d6557..f5be00252c2 100644 --- a/deployment/docker-compose.yml +++ b/docker-compose.yml @@ -1,8 +1,10 @@ -version: "3" +version: "3.9" services: - api: - build: . + fuel-core: + build: + context: . + dockerfile: deployment/Dockerfile image: fuel-core ports: - "4000:4000"