Skip to content

Commit

Permalink
Docker build
Browse files Browse the repository at this point in the history
  • Loading branch information
PartTimeLegend committed Mar 26, 2024
1 parent c219ea8 commit 0f30ac6
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
44 changes: 44 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Build and Publish Docker Image

on:
push:
branches:
- master

jobs:
build-and-publish:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4 # Check out your repository's code

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Log in to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Generate build date
id: build_date
run: echo "::set-output name=BUILD_DATE::$(date -u +'%Y-%m-%dT%H:%M:%SZ')"

- name: Build the Docker image
run: |
docker build \
--file Dockerfile \
--tag ghcr.io/${{ github.repository_owner }}/hammy-mchamiton:${{ github.run_number }} \
--tag ghcr.io/${{ github.repository_owner }}/hammy-mchamilton:latest \
--build-arg BUILD_DATE=${{ steps.build_date.outputs.BUILD_DATE }} \
.
env:
BUILD_DATE: ${{ steps.build_date.outputs.BUILD_DATE }}

- name: Push the Docker image to GitHub Container Registry
run: |
docker push ghcr.io/${{ github.repository_owner }}/hammy-mchamilton:${{ github.run_number }}
docker push ghcr.io/${{ github.repository_owner }}/hammy-mchamilton:latest
23 changes: 23 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Use official Python runtime as a parent image
FROM python:3.9-slim

# Set the working directory in the container
WORKDIR /app

# Copy the current directory contents into the container at /app
COPY . /app

# Install any needed dependencies specified in requirements.txt
RUN pip install --no-cache-dir -r requirements.txt

# Define environment variable
ENV PYTHONUNBUFFERED=1

# Add standard labels
LABEL maintainer="Joshua Clarke and Antony Bailey <antony.bailey@thepoliceoftheinter.net>"
LABEL description="This is a Docker image for the Hammy McHamilton Discord Bot."
LABEL org.opencontainers.image.created="$BUILD_DATE"
# docker build --build-arg BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ') -t hammy-mchamilton .

# Run main.py when the container launches
CMD ["python", "main.py"]

0 comments on commit 0f30ac6

Please sign in to comment.