From 8808153cefefff32d2a2fea207f2dc98876e9ebe Mon Sep 17 00:00:00 2001 From: Felipe Molina <846513+felmoltor@users.noreply.github.com> Date: Tue, 20 Aug 2024 16:50:32 +0200 Subject: [PATCH] Add workflow and update devcontainer to map .ssh folder --- .devcontainer/devcontainer.json | 3 ++ .github/workflows/publish-registry.yml | 64 ++++++++++++++++++++++++++ .gitignore | 1 - Dockerfile | 15 +++++- 4 files changed, 81 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/publish-registry.yml diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 59ecbad..2592cb5 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -5,6 +5,9 @@ "build": { "args": {} }, + "mounts": [ + "source=${env:HOME}/.ssh,target=/root/.ssh,type=bind,consistency=cached" + ], "customizations": { "vscode": { "settings": { diff --git a/.github/workflows/publish-registry.yml b/.github/workflows/publish-registry.yml new file mode 100644 index 0000000..2b57953 --- /dev/null +++ b/.github/workflows/publish-registry.yml @@ -0,0 +1,64 @@ +name: Publish Docker image and Create Release + +permissions: + contents: write + +on: + push: + tags: + - 'v*' + +jobs: + publish: + runs-on: ubuntu-latest + + env: + IMAGE_NAME: maitm # Define the image name variable + + steps: + - name: Print Variables and Extract Git Tag + shell: bash + run: | + echo "ref_type: ${{github.ref_type}}" + echo "ref: ${{github.ref}}" + echo "base_ref: ${{github.base_ref}}" + echo "github.repository: ${{github.repository}}" + echo "GIT_TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV + + - name: Checkout code + uses: actions/checkout@v2 + + - name: Log in to GitHub Container Registry + run: echo "${{ secrets.GHCR_PAT }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin + + - name: Build Docker image + run: | + docker build -t ghcr.io/${{ github.repository }}/${{env.IMAGE_NAME}}:${{ github.ref_name }} . + + - name: Build Docker Image + run: | + docker build \ + --build-arg VERSION=${{ env.GIT_TAG }} \ + --build-arg GITHUB_SHA=${{ github.sha }} \ + --build-arg BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ') \ + -t ghcr.io/${{ github.repository }}/${{env.IMAGE_NAME}}:${{ github.ref_name }} \ + -t ghcr.io/${{ github.repository }}/${{env.IMAGE_NAME}}:latest \ + . + + - name: Push Docker image to GitHub Container Registry + run: | + docker push ghcr.io/${{ github.repository }}/${{env.IMAGE_NAME}}:${{ github.ref_name }} + docker push ghcr.io/${{ github.repository }}/${{env.IMAGE_NAME}}:latest + + + - name: Create GitHub Release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Automatically provided by GitHub Actions + with: + tag_name: ${{ github.ref_name }} # Use the tag name as the release title + release_name: Release ${{ github.ref_name }} + body: | + This is the release of version ${{ github.ref_name }}. + draft: false + prerelease: false diff --git a/.gitignore b/.gitignore index b64b230..d1f97d1 100644 --- a/.gitignore +++ b/.gitignore @@ -116,7 +116,6 @@ dist .pnp.* .vscode -.github config.yml config*.yaml forwardedemails.txt diff --git a/Dockerfile b/Dockerfile index b5fa662..23049a7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,20 @@ FROM alpine:3.20 LABEL name="Maitm" + + +# Accept build arguments +ARG VERSION +ARG GITHUB_SHA +ARG BUILD_DATE + +# Labels with dynamic values LABEL "com.example.vendor"="Orange Cyberdefense Sensepost Team" -LABEL org.opencontainers.image.authors="Felipe Molina de la Torre" +LABEL org.opencontainers.image.authors="Felipe Molina de la Torre (@felmoltor)" +LABEL org.opencontainers.image.source="https://github.com/sensepost/mail-in-the-middle" +LABEL org.opencontainers.image.url="https://github.com/sensepost/mail-in-the-middle" +LABEL org.opencontainers.image.version=$VERSION +LABEL org.opencontainers.image.revision=$GITHUB_SHA +LABEL org.opencontainers.image.created=$BUILD_DATE COPY *.py /Maitm/ COPY Pipfile /Maitm/