Skip to content

Commit

Permalink
Updating Docker processing (#19)
Browse files Browse the repository at this point in the history
* v0.0.0.1

* v0.0.0.2

* v0.0.0.3

* v0.0.0.4

* v0.0.0.5

* v0.0.0.6

* Bump Dockerfile tag to match release 'v0.0.0.6'

* v0.0.0.7

* v0.0.0.8

* Bump Dockerfile tag to match release 'v0.0.0.8'

* v0.0.0.9

* v0.0.0.10

* Bump Dockerfile tag to match release 'v0.0.0.10'

* v0.0.0.11

* Bump Dockerfile tag to match release 'v0.0.0.11'

* v0.0.0.12

* v0.0.0.13

* v0.0.0.14

* Bump Dockerfile tag to match release 'v0.0.0.14'

* testing docker file updates

* updating ref name

* Bump Dockerfile tag to match release 'v0.0.1-rc1'

* updating to use ghcr version for docker

* updating push condition

* updating for master branch

---------

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
its-a-feature and github-actions[bot] authored Jan 20, 2024
1 parent af2b1c0 commit 19d2b1d
Show file tree
Hide file tree
Showing 4 changed files with 165 additions and 3 deletions.
132 changes: 132 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
# Pulled from Thanatos (https://github.com/MythicAgents/thanatos/blob/rewrite/.github/workflows/image.yml) - MEhrn00

# Name for the Github actions workflow
name: Build and push container images

on:
# Only run workflow when there is a new release published in Github
#release:
# types: [published]
push:
branches:
- 'master'
- 'main'
tags:
- "v*.*.*"

# Variables holding configuration settings
env:
# Container registry the built container image will be pushed to
REGISTRY: ghcr.io

# Set the container image name to the Github repository name. (MythicAgents/apfell)
AGENT_IMAGE_NAME: ${{ github.repository }}

# Description label for the package in Github
IMAGE_DESCRIPTION: ${{ github.repository }} agent container for use with Mythic

# Source URL for the package in Github. This links the Github repository packages list
# to this container image
IMAGE_SOURCE: ${{ github.server_url }}/${{ github.repository }}

# License for the container image
IMAGE_LICENSE: BSD-3-Clause

# Set the container image version to the Github release tag
VERSION: ${{ github.ref_name }}
#VERSION: ${{ github.event.head_commit.message }}

RELEASE_BRANCH: master

jobs:
# Builds the base container image and pushes it to the container registry
agent_build:
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
steps:
- name: Checkout the repository
uses: actions/checkout@v4 # ref: https://github.com/marketplace/actions/checkout
- name: Log in to the container registry
uses: docker/login-action@v3 # ref: https://github.com/marketplace/actions/docker-login
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
with:
platforms: 'arm64,arm'
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2
# the following are unique to this job
- name: Lowercase the server container image name
run: echo "AGENT_IMAGE_NAME=${AGENT_IMAGE_NAME,,}" >> ${GITHUB_ENV}
- name: Build and push the server container image
uses: docker/build-push-action@v5 # ref: https://github.com/marketplace/actions/build-and-push-docker-images
with:
context: Payload_Type/apfell
file: Payload_Type/apfell/.docker/Dockerfile
tags: |
${{ env.REGISTRY }}/${{ env.AGENT_IMAGE_NAME }}:${{ env.VERSION }}
${{ env.REGISTRY }}/${{ env.AGENT_IMAGE_NAME }}:latest
push: ${{ github.ref_type == 'tag' }}
# These container metadata labels allow configuring the package in Github
# packages. The source will link the package to this Github repository
labels: |
org.opencontainers.image.source=${{ env.IMAGE_SOURCE }}
org.opencontainers.image.description=${{ env.IMAGE_DESCRIPTION }}
org.opencontainers.image.licenses=${{ env.IMAGE_LICENSE }}
platforms: linux/amd64,linux/arm64

update_files:
runs-on: ubuntu-latest
needs:
- agent_build
permissions:
contents: write
packages: write

steps:
# Pull in the repository code
- name: Checkout the repository
uses: actions/checkout@v4 # ref: https://github.com/marketplace/actions/checkout

# update names to lowercase
- name: Lowercase the container image name
run: echo "AGENT_IMAGE_NAME=${AGENT_IMAGE_NAME,,}" >> ${GITHUB_ENV}

# The Dockerfile which Mythic uses to pull in the base container image needs to be
# updated to reference the newly built container image
- name: Fix the server Dockerfile reference to reference the new release tag
working-directory: Payload_Type/apfell
run: |
sed -i "s|^FROM ghcr\.io.*$|FROM ${REGISTRY}/${AGENT_IMAGE_NAME}:${VERSION}|" Dockerfile
# Push the changes to the Dockerfile
- name: Push the updated base Dockerfile image reference changes
if: ${{ github.ref_type == 'tag' }}
uses: EndBug/add-and-commit@v9 # ref: https://github.com/marketplace/actions/add-commit
with:
# Only add the Dockerfile changes. Nothing else should have been modified
add: "['Payload_Type/apfell/Dockerfile']"
# Use the Github actions bot for the commit author
default_author: github_actions
committer_email: github-actions[bot]@users.noreply.github.com

# Set the commit message
message: "Bump Dockerfile tag to match release '${{ env.VERSION }}'"

# Overwrite the current git tag with the new changes
tag: '${{ env.VERSION }} --force'

# Push the new changes with the tag overwriting the current one
tag_push: '--force'

# Push the commits to the branch marked as the release branch
push: origin HEAD:${{ env.RELEASE_BRANCH }} --set-upstream

# Have the workflow fail in case there are pathspec issues
pathspec_error_handling: exitImmediately
22 changes: 22 additions & 0 deletions Payload_Type/apfell/.docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM python:3.11-slim-bookworm as builder

COPY [".docker/requirements.txt", "requirements.txt"]
RUN apt-get -y update && \
apt-get -y upgrade && \
apt-get install --no-install-recommends \
software-properties-common apt-utils make build-essential libssl-dev zlib1g-dev libbz2-dev \
xz-utils tk-dev libffi-dev liblzma-dev libsqlite3-dev protobuf-compiler \
binutils-aarch64-linux-gnu libc-dev-arm64-cross -y
RUN python3 -m pip wheel --wheel-dir /wheels -r requirements.txt

FROM python:3.11-slim-bookworm

COPY --from=builder /wheels /wheels

RUN pip install --no-cache /wheels/*

WORKDIR /Mythic/

COPY [".", "."]

CMD ["python3", "main.py"]
7 changes: 7 additions & 0 deletions Payload_Type/apfell/.docker/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
aio-pika==9.0.4
dynaconf==3.1.11
ujson==5.7.0
aiohttp==3.8.3
psutil==5.9.4
pycryptodome
mythic-container==0.4.5
7 changes: 4 additions & 3 deletions Payload_Type/apfell/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
FROM itsafeaturemythic/mythic_python_base:latest
FROM ghcr.io/mythicagents/apfell:v0.0.1-rc1
#FROM itsafeaturemythic/mythic_python_base:latest

WORKDIR /Mythic/
#WORKDIR /Mythic/

CMD ["python3", "main.py"]
#CMD ["python3", "main.py"]

0 comments on commit 19d2b1d

Please sign in to comment.