Skip to content

Commit

Permalink
updated everything from dockerise-basic to development
Browse files Browse the repository at this point in the history
  • Loading branch information
HauwaHakimi committed Feb 7, 2024
2 parents a2ab541 + c35bc85 commit 0086331
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 2 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

name: Tests
on:
workflow_dispatch:
push:
branches:
- 'master'
- 'main'
- 'dockerise'
- 'publish-to-dockerhub'
- 'push-to-ghcr-and-ecr'
- 'dockerise-basic'
pull_request:
branches:
- 'master'
- 'main'
- 'dockerise'
- 'publish-to-dockerhub'
- 'push-to-ghcr-and-ecr'
- 'dockerise-basic'
jobs:
48 changes: 48 additions & 0 deletions .github/workflows/ghcr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#
name: Create and publish a Docker image

# Configures this workflow to run every time a PR is raised to the branch called `main`.
on:
pull_request:
branches: ['main']

# Defines two custom environment variables for the workflow. These are used for the Container registry domain, and a name for the Docker image that this workflow builds.
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

# There is a single job in this workflow. It's configured to run on the latest available version of Ubuntu.
jobs:
build-and-push-image:
runs-on: ubuntu-latest
# Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job.
permissions:
contents: read
packages: write
#
steps:
- name: Checkout repository
uses: actions/checkout@v4
# Uses the `docker/login-action` action to log in to the Container registry registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here.
- name: Log in to the Container registry
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) to extract tags and labels that will be applied to the specified image. The `id` "meta" allows the output of this step to be referenced in a subsequent step. The `images` value provides the base name for the tags and labels.
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
# This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages.
# It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see "[Usage](https://github.com/docker/build-push-action#usage)" in the README of the `docker/build-push-action` repository.
# It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step.
- name: Build and push Docker image
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
49 changes: 49 additions & 0 deletions .github/workflows/publish-docker-image.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,45 @@ on:
push:
branches:
- 'main'
<<<<<<< HEAD
- 'master'
- 'development'
=======
>>>>>>> dockerise-basic
- 'releases/**'

jobs:
push_to_registry:
<<<<<<< HEAD
name: Push Docker image to GHCR
=======
name: Push Docker image to Docker Hub
>>>>>>> dockerise-basic
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v4

<<<<<<< HEAD
- name: Log in to Github Container Registry
uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
=======
- name: Log in to Docker Hub
uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
>>>>>>> dockerise-basic

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
<<<<<<< HEAD
images: ghcr.io/alphagov/re-request-an-aws-account/governmentdigitalservice/ee-request-aws-account
tags: |
type=sha,enable=true,priority=100,prefix=sha-,suffix=,format=short
Expand All @@ -39,10 +55,43 @@ jobs:
# BUG: This is not echoing locally with `act`

- name: Build and push Docker image
=======
images: governmentdigitalservice/ee-request-aws-account
tags: |
type=semver,pattern={{version}}
type=sha,enable=true,priority=100,prefix=sha-,suffix=,format=short
type=raw,value=latest,enable={{is_default_branch}}
- name: Output tags
run: |
echo "::notice tags: ${{steps.meta.outputs.tags}}"
- name: Build and push Docker image
id: docker_image
>>>>>>> dockerise-basic
uses: docker/build-push-action@3b5e8027fcad23fda98b2e3ac259d8d67585f671
with:
context: .
file: ./Dockerfile
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
<<<<<<< HEAD
=======

- name: Push Docker image into ECR
uses: docker://ghcr.io/kciter/aws-ecr-action:latest
with:
access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID }}
secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
account_id: ${{ secrets.AWS_ACCOUNT_ID }}
repo: docker/repo
region: eu-west-2
tags: latest,${{ github.sha }}
create_repo: true
image_scanning_configuration: true
set_repo_policy: true
repo_policy_file: repo-policy.json


>>>>>>> dockerise-basic
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ COPY . .
RUN bundle install
RUN npm install


EXPOSE 3000

# Run a shell
#CMD ["bundle", "exec", "rails", "server"]
CMD ["bundle", "exec", "rails", "server", "-b", "0.0.0.0", "--port", "8888"]
CMD ["bundle", "exec", "rails", "server", "-b", "0.0.0.0", "--port", "3000"]



0 comments on commit 0086331

Please sign in to comment.